I am attempting to create a function in Matlab which turns all matrix elements in a matrix to '0' if the element is not symmetrical. However, the element appears to not be reassigning.
function [output_ting] = maker(a)
[i,j] = size(a);
if i ~= j
disp('improper input!')
else
end
c = 1;
b = a.';
while c < length(a) + 1
if a(c) == b(c)
c = c + 1;
continue
else
a(c) = 0;
c = c + 1;
end
end
disp(a)
end
$a$ is a matrix, a 2D structure. You appear to want to use 1D indexing, but the length is giving you the number of rows. Use length(a(:)), or numel(a).