Filter löschen
Filter löschen

how to store the output of for loop

1 Ansicht (letzte 30 Tage)
bana althawabteh
bana althawabteh am 22 Jun. 2021
Bearbeitet: Jan am 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

Antworten (1)

Jan
Jan am 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 Kommentare
bana althawabteh
bana althawabteh am 24 Jun. 2021
and the second option dosent work correctly
Jan
Jan am 25 Jun. 2021
Bearbeitet: Jan am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by