Clear Filters
Clear Filters

how to store the output of for loop

1 view (last 30 days)
bana althawabteh
bana althawabteh on 22 Jun 2021
Edited: Jan on 25 Jun 2021
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

Answers (1)

Jan
Jan on 22 Jun 2021
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 Comments
bana althawabteh
bana althawabteh on 24 Jun 2021
and the second option dosent work correctly
Jan
Jan on 25 Jun 2021
Edited: Jan on 25 Jun 2021
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!