Combine the results of each iteration into an array
2 次查看(过去 30 天)
显示 更早的评论
a=1;b=2;c=3;
For t=[a b c]
if t==1
disp(a)
elseif t==2
disp(b)
elseif t==3
disp(c)
end
end
I want to get answer in only one line Like a b c or abc
0 个评论
回答(1 个)
Ameer Hamza
2020-12-7
Use fprintf()
a=1;b=2;c=3;
for t=[a b c]
fprintf('%d ', t)
end
fprintf(newline)
3 个评论
Ameer Hamza
2020-12-7
Are you looking for something like this
a=1;b=2;c=3;
for t=[a b c]
if t==1
fprintf('%s ', 'a')
elseif t==2
fprintf('%s ', 'b')
elseif t==3
fprintf('%s ', 'c')
end
end
fprintf(newline)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!