"For Iteration" output index appears to perform parallel selector indexing in series instead

1 vue (au cours des 30 derniers jours)
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).

Réponses (1)

Walter Roberson
Walter Roberson le 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
  2 commentaires
Mike
Mike le 5 Nov 2024
My issue was related to my initial conditions, rather than the "for iteration" block. i appreciate the help regardless!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by