How to store values of iterations

1 vue (au cours des 30 derniers jours)
Afzal
Afzal le 21 Mar 2013
I have a for loop with an if condition. I want to store all the values of 'i' for which the codition is met. Right now it only stores the last value of i.
for i=1:length(data)
x = i+1;
if i == length(data)
x = length(data);
end
if (magnitude_velocity(x,1)<0.01) && (magnitude_velocity(i,1)>0.01)
index = i;
end
end

Réponse acceptée

Wouter
Wouter le 21 Mar 2013
index = [];
for i=1:length(data)
x = i+1;
if i == length(data)
x = length(data);
end
if (magnitude_velocity(x,1)<0.01) && (magnitude_velocity(i,1)>0.01)
index = [index i];
end
end
  1 commentaire
Wouter
Wouter le 21 Mar 2013
And this is a bit shorter:
index = [];
for i=1:length(data)-1
if (magnitude_velocity(i+1,1)<0.01) && (magnitude_velocity(i+1,1)>0.01)
index = [index i];
end
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Spline Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by