"For Iteration" output index appears to perform parallel selector indexing in series instead
조회 수: 1 (최근 30일)
이전 댓글 표시
I am attempting to use a selector to compare the same index values from two different vectors for a logical operation. However, it appears the first selector goes through all index values (holds the last value) and then the next selector appears to index through all values so that the comparison logic is only using the last possible selection from the first selector to compare with each of the second selector values. Instead of the same index value for each selector (parallel).
답변 (1개)
Walter Roberson
2024년 11월 1일
It sounds as if you have something of the form
for J = 1:length(FirstVector)
%some operation
end
for K = 1:length(SecondVector)
%some other operation
end
where you should instead be using
for J = 1 : length(FirstVector)
for K = 1 : length(SecondVector)
%some operation
end
end
But more likely you need
for J = 1 : min(length(FirstVector), length(SecondVector))
t1 = FirstVector(J);
t2 = SecondVector(J);
%some operation on t1, t2
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!