MATLAB: How to store values of iterations

indexiterations

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

Best Answer

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