Problem with string assembly
1 回表示 (過去 30 日間)
古いコメントを表示
Hy all for my code,
V_AA = [100; 200]
L_AA = length(V_AA)
S_AA = num2str(V_AA)
for i=1:L_AA
F_AA{i} = ['N°: ' S_AA(i)];
end
i'm unable to get :
F_AA{1} = N°: 100
F_AA{2} = N°: 200
Thanks
0 件のコメント
採用された回答
Azzi Abdelmalek
2016 年 8 月 14 日
編集済み: Azzi Abdelmalek
2016 年 8 月 14 日
V_AA = [100; 200]
L_AA = length(V_AA)
for i=1:L_AA
F_AA{i} = sprintf('N°: %d', V_AA(i))
end
%or without for loop
F_AA=regexp(sprintf('N°: %d ', V_AA'),'N°: \d+','match')
その他の回答 (1 件)
Geoff Hayes
2016 年 8 月 14 日
Judy - since S_AA is an array of characters, then
S_AA(i)
returns the first character only in the ith row. To return all characters, you would need to do
for i=1:L_AA
F_AA{i} = ['N°: ' S_AA(i,:)];
end
参考
カテゴリ
Help Center および File Exchange で Engines & Motors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!