フィルターのクリア

Combine the results of each iteration into an array

2 ビュー (過去 30 日間)
Ayat Qasim
Ayat Qasim 2020 年 12 月 7 日
コメント済み: Ameer Hamza 2020 年 12 月 7 日
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

回答 (1 件)

Ameer Hamza
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 件のコメント
Ayat Qasim
Ayat Qasim 2020 年 12 月 7 日
Your idea gives only number which is integer
Ameer Hamza
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 ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by