"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
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
  댓글 수: 2
Mike
Mike 2024년 11월 5일
My issue was related to my initial conditions, rather than the "for iteration" block. i appreciate the help regardless!

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by