"For Iteration" output index appears to perform parallel selector indexing in series instead
1 view (last 30 days)
Show older comments
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).
Answers (1)
Walter Roberson
on 1 Nov 2024
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
See Also
Categories
Find more on Matrix Indexing 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!