I have a matrix sorted in ascending order.
S = 25;
RT = zeros(S,2);
for i = 1:S;
for j = 1:i;
R = i *j;
T = R + j;
RT(j,:) = [R T];
end
end
sortRT = sortrows(RT, [1 2]);
disp(sortRT);
I want to find the sortRT elements which values is lower than 500 (for R) and 490 (for T) per column and place these values inside a matrix. Is it possible?
Just use find:
These are the rows where both
R<500andT<490. You can of course separate these two:If you’re just going to copy elements or rows, then find isn’t even necessary and you can use logical indexing:
is the same as
This copies elements of the first column, if you want to copy the whole row, use the colon operator: