Find Function in a for loop - store rows and columns

조회 수: 1 (최근 30일)
Dennis_Pana
Dennis_Pana 2015년 10월 19일
댓글: Dennis_Pana 2015년 10월 19일
for i=1:p
Min_Dis2(exchanges,i)=min(nonzeros(distance2(:,:,i)));
[row,col]=find(distance2(:,:,i)==Min_Dis2(exchanges,i))
end
This is the part of my code which bothers me. When the for loop reaches 'p' i want to have the rows and the columns of each matrix stored. Right now if i run this code i get the row and the column of the last iteration. In other words i need a counter for the rows and columns, something like that [row,col](i), i know that this is not correct, but this is what i need. Thank you in advance!

채택된 답변

TastyPastry
TastyPastry 2015년 10월 19일
Why don't you just find the size of your matrix after your loop?
rows = size(myMat,1);
cols = size(myMat,2);
  댓글 수: 2
Dennis_Pana
Dennis_Pana 2015년 10월 19일
I do not understand your answer. I am looking for the row and column of a specific value of distance2(n,n,p). distance2 are p matrices with nbyn dimensions. If p=3 then i want the row and the column of the minium value of each matrix (if p=3 we have 3 matrices). Thank you!
Dennis_Pana
Dennis_Pana 2015년 10월 19일
I just found a solution!! Do not waste your time with me! Thank you for your interest!! I did A(:,i)=row; B(:,i)=col;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by