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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vaibav Reddy
am 13 Aug. 2022
Kommentiert: Walter Roberson
am 13 Aug. 2022
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.
Akzeptierte Antwort
Walter Roberson
am 13 Aug. 2022
for iIdx = 1:4
for jIdx = 1:4
total = iIdx + jIdx;
num(iIdx, jIdx) = rem(sum, 2);
end
end
4 Kommentare
Torsten
am 13 Aug. 2022
num(iIdx, jIdx) = rem(total, 2);
instead of
num(iIdx, jIdx) = rem(sum, 2);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!