Is it possible with for loop s1,s2,s3 variable looping ?

1 次查看(过去 30 天)
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 个评论
Geoff Hayes
Geoff Hayes 2015-10-30
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

请先登录,再进行评论。

采纳的回答

per isakson
per isakson 2015-10-30
编辑:per isakson 2015-10-30

更多回答(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