I want to store the value generated by the for loop into a new variable so I can use it further in my code. How do I do it ?

조회 수: 1 (최근 30일)
My code :
for iIdx = 1:4
for jIdx = 1:4
sum = iIdx + jIdx;
if rem(sum,2) == 1
num = 1;
else
num = 0;
end
fprintf("%d ",num);
end
fprintf("\n");
end
I created this matrix and I got my expected output. I just want to know how to store this value into a new variable. Can you help me with it. Thank you.

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 13일
for iIdx = 1:4
for jIdx = 1:4
total = iIdx + jIdx;
num(iIdx, jIdx) = rem(sum, 2);
end
end
  댓글 수: 4

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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