MATLAB: How to assign vales to matrix

matrix value assigning

I need to put 1 or -1 and 2 or -2 in a square matrix by putting the condition using the for loop.But it is not working. Can any one help me please? Thanks in advance..
the code is
AA=rand([5]);
aa=rand([5]);
for i= 5
for j= 5
if (AA(i,j)>=0.5)
BB(i,j)= 1;
CC(i,j)= 2;
else
BB(i,j)= -1;
CC(i,j)= -2;
end
if (aa(i,j)>=0.5)
bb(i,j)= 1;
cc(i,j)= 2;
else
bb(i,j)= -1;
cc(i,j)= -2;
end
end
end

Best Answer

You have define i and j in the for loop for the entire range. For example,
for i=1:5
%%...
end
Related Question