필터 지우기
필터 지우기

'for loop' trouble

조회 수: 1 (최근 30일)
Michael
Michael 2011년 5월 19일
basically i have two lists of doubles, each a single column, one longer than the other. every number in A is located somewhere in B, I just need to find where. So I tried to use a for loop, but ran into an issue.
A = [12; 15; 16; 19; 20];
B = [10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20];
My code is as follows:
for j=1:length(A)
ind = find(A==B)
end
the output basically keeps replacing 'ind' with a new value, when in fact i need to store all values of 'ind' that it generates. might be a simple fix but im still learning. thanks in advance
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 5월 19일
As with your question earlier, good job writing questions that are easy for us to understand and answer!

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

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 5월 19일
[junk,idx] = ismember(A,B)
idx is the location you're looking for.
(and to fix your for-loop)
for ii = length(A):-1:1
ind(ii) = find(A(ii)==B);
end

추가 답변 (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