"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!