Filter löschen
Filter löschen

Saving output results in a for loop

12 Ansichten (letzte 30 Tage)
Macarena Santillan
Macarena Santillan am 13 Jul. 2021
Hello, I am trying to make a loop that will iterate based on the previous value and I want to save the results from each iteration in a table/array. I created the empty array beforehand but when I execute the code it return the empty array with the values from the last iteration on the last row.
I am also not sure if the code is actually using the previous value in the way I set it up, but Its not giving errors, so I am assuming its fine(?
Thank you for any help you can provide
results=zeros(500,3);
for i=1000:100:1500
for j=150:50:1608
[y,x]=min (ds(j:j+100,i));
minpix(i)=j+x;
[y1,x1]=min (ds(minpix(i)-50:minpix(i)+50,i-1));
minpix(i-1)=minpix(i)+x1;
PixSh= minpix(i-1)-minpix(i);
ChangeVel=PixSh/90;
results(i,:)=[i ChangeVel PixSh];
end
end

Akzeptierte Antwort

KSSV
KSSV am 14 Jul. 2021
results=zeros([],3);
count = 0 ;
for i=1000:100:1500
for j=150:50:1608
[y,x]=min (ds(j:j+100,i));
minpix(i)=j+x;
[y1,x1]=min (ds(minpix(i)-50:minpix(i)+50,i-1));
minpix(i-1)=minpix(i)+x1;
PixSh= minpix(i-1)-minpix(i);
ChangeVel=PixSh/90;
count = count+1 ;
results(count,:)=[i ChangeVel PixSh];
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by