how to store the output of for loop

1 回表示 (過去 30 日間)
bana althawabteh
bana althawabteh 2021 年 6 月 22 日
編集済み: Jan 2021 年 6 月 25 日
i have this code and i ned to store the value of center_x and center_y in each iteration
for (ii=0:d2:d2*(GW-1)
for(i=1:2:2*GL)
plot(i*center_x,center_y,'o')
end
center_y=center_y+d2;
end

回答 (1 件)

Jan
Jan 2021 年 6 月 22 日
for ii = 0:d2:d2*(GW-1)
for i = 1:2:2*GL
plot(i * center_x, center_y, 'o');
end
center_y = center_y + d2;
end
stored_x = (1:2:2*GL) * center_x;
stored_y = (0:d2:d2*(GW-1)) * d2;
Or start from the creating the positions:
x = (1:2:2*GL) * center_x;
y = (0:d2:d2*(GW-1)) * d2;
for i1 = 1:numel(x)
for i2 = 1:numel(y)
plot(x(i1), y(i2), 'o');
end
end
  3 件のコメント
bana althawabteh
bana althawabteh 2021 年 6 月 24 日
and the second option dosent work correctly
Jan
Jan 2021 年 6 月 25 日
編集済み: Jan 2021 年 6 月 25 日
I do no have the chance to know, what you want as output. All I can see is the code you have posted and your question, that you want to store "center_x and center_y" in each iteration. But center_x does not change its value. Your code dos not run, because the initial values are missing. So all what I can do is showing some methods which store values inside a loop or produce them without a loop. Of course you have to do some tuning to let the code solve your problem. Based on the given information, I cannot do this for you.
"Doesn't work correctly" does not allow to understand, what you observe and what you want instead.

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

カテゴリ

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