for loop return answer in string matrix

1 回表示 (過去 30 日間)
Jidapa Adam
Jidapa Adam 2021 年 11 月 28 日
回答済み: Jan 2021 年 11 月 28 日
I have Ci in dimension (61x3)
and I want the ans in each row
example ans(1,1) True ans(1,2) True ans(1,3) True
This is code that I write
Ci = [Ca Cb Cc] ;
for i = 1:length(Ci),
for j = 1:3
if Ci(i,j)>0
a = 'True';
else
a = 'False';
end
fprintf ('ans %d,%d = %s\n',i,j,a);
end
end
Thank you for answer

回答 (1 件)

Jan
Jan 2021 年 11 月 28 日
Ci = randn(5, 4);
pool = ["False", "True"];
a = pool((Ci > 0) + 1)
a = 5×4 string array
"False" "True" "True" "True" "True" "True" "True" "False" "True" "False" "True" "False" "False" "False" "True" "True" "False" "False" "False" "True"

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by