How do I create a loop and put the results that satisfy the loop into a new variable?
Ältere Kommentare anzeigen
I am trying to create a loop that takes the difference between successive items in a vector, and if the difference is less than a value (0.1 in the example below), then put the item in a new vector, called fastTimesChop. I don't know what I am doing wrong, but I get either errors or values in fastTimesChop that are not right. Below is what I have done so far.
fastTimes=(0.033:rand:300);
fastTimesChop=[];
for j=1:(length(fastTimes-1))
if((fastTimes(j+1))-(fastTimes(j)))<0.815
fastTimesChop=[fastTimes(j); fastTimes(j+1)];
end
end
Thank you for any help!!!
Antworten (1)
Andrei Bobrov
am 23 Dez. 2015
Bearbeitet: Andrei Bobrov
am 23 Dez. 2015
a = fastTimes(:);
ii = find(diff(a)<0.815);
fastTimesChop = [a(ii),a(ii+1)];
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!