Saving output results in a for loop

12 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2021-7-14
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by