for loop question, how to put the for loop answer in new matrix
Show older comments
Dear all, I got some problems with my code. I suppose it is basic. However, I can't find where is the problem. I want to find a position in my matrix. First, I would like to find out the number>=9 positions for each column. When I get the position, I would like to get the nearest one and the far one. And I use k=x1-x2, so I can get the distances for each column. if none of the numbers can fit into the statement( x1-x2 empty vector), then skip. In the end, I want to put the information into a new matrix called 'final'. Thank you for your help!
A = [88,2,77,4,5;6,2,9,5,0;6,7,3,4,5;6,7,8,5,6;7,8,9,10,6;7,8,9,99,15;45,55,2,2,2;67,66,56,87,1];
for j = 1:size(A)
line=A(j,:);
C=find(line>=9);
x1=max(C);
x2=min(C);
k=x1-x2
final(j,:)=k
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!