Is it possible with for loop s1,s2,s3 variable looping ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
x y
am 30 Okt. 2015
Bearbeitet: per isakson
am 30 Okt. 2015
Hy I wonder it is possible something this (looping with variable name) :
s1 = 5;
s2 = 6;
s3 = 7;
for i = 1:3
s[(i)] or s(i)
end
1 Kommentar
Geoff Hayes
am 30 Okt. 2015
xy - why not just store your three variables in an array as
s = [5 6 7];
and then access each element as
for k = 1:3
% do something with s(k)
end
Akzeptierte Antwort
per isakson
am 30 Okt. 2015
Bearbeitet: per isakson
am 30 Okt. 2015
First see:
- How can I create variables A1, A2,...,A10 in a loop? Please don't do this!
- Alternatives to the eval Function
then try
s = zeros( 1,3);
for ii = 1 : 3
s(ii) = rand;
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
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!