Filter löschen
Filter löschen

Print matrices whose name is based on loop values

1 Ansicht (letzte 30 Tage)
Paras Choudhary
Paras Choudhary am 21 Jul. 2022
Beantwortet: Steven Lord am 21 Jul. 2022
for i = 1:3
eval(['k' num2str(i) '=i']);
end
%% Doubt - How to print k1, k2, k3 based on iteration no. ???

Akzeptierte Antwort

Steven Lord
Steven Lord am 21 Jul. 2022
Can you dynamically create variables with numbered names like k1, k2, k3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.

Weitere Antworten (0)

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