how to store the output of for loop

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by