필터 지우기
필터 지우기

Saving output results in a for loop

조회 수: 12 (최근 30일)
Macarena Santillan
Macarena Santillan 2021년 7월 13일
댓글: Macarena Santillan 2021년 7월 14일
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