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 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by