フィルターのクリア

How can I make this nested for loop work?

1 回表示 (過去 30 日間)
Deepanwita
Deepanwita 2013 年 5 月 13 日
I want to store values in 'temp1' and 'temp2' dynamically. I have predefined them so no problem with the speed. This is my code for getting the value of 'bc' using for loop of 'obj'. This is inside the for loop run by 'i'. In the very first run of outer for loop i.e. i=1, I need to have the inner for loop run first completely and then the values of bc(1) be stored in temp1(1) and bc(2) in temp2(2). And then value of 'i' should increment by 1 and next time the values of bc(1) and bc(2) be stored in temp1(2) and temp2(2) respectively and so on.
for i=1:10
for obj = 1:length(stats)
bc = stats(obj).Centroid;
end
temp1(i)=bc(1);
temp2(i)=bc(2);
end
What's happening now is that the last value of bc(1) and bc(2) are getting stored in temp1 and temp2 all through i=1:10. Please correct me.

採用された回答

David Sanchez
David Sanchez 2013 年 5 月 13 日
your variable bc has no index, it can not change along the loop. temp1 and temp2 always take the value of bc(1) and bc(2) respectively for all i
  1 件のコメント
Deepanwita
Deepanwita 2013 年 5 月 13 日
how do i correct it?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by