MATLAB: How to create a signal matrix

biggerfor looprulesignalsmaller than

Hello, I am trying to replicate a matrix (signals2) that gives me signals of 1,0 or 1 depending on the value of each single observation in another matrix (rankfull2)-the two have the same size. I would like matrix "signals2" to show 1 when the value is above 319, -1 when is below 60 and 0 otherwise.
for iii=1:size(rankfull2,1)
for jjj= 1:size(rankfull2(1,:),2)
if rankfull2(iii,jjj) < 60
signals2(iii,jjj)= -1;
elseif rankfull2(1,jjj) > 319
signals2(iii,jjj)= 1;
else signals2(iii,jjj)= 0;
end
end
end
The output that I get seems to understand the rule of lower than 60 but not the one above 319, returning a 0 instead of a 1 (each row contains at leat 50 values above 319)
Could you someone advise if there is something wrong with my loop or if I am unaware of certain matlab rules?
Thank you in advance.

Best Answer

It looks like the issue might be because you are only looking in the first row of rankfull2 with your >319 line of code. Anyway, there is a much cleaner way of doing this without the need for loops. You should take a look at logical indexing.
signals2 = zeros(size(rankfull2));
signals2(rankfull2 < 60) = -1;
signals2(rankfull2 > 319) = 1;