필터 지우기
필터 지우기

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 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