Concatenate string output to another string vertically in a loop
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a loop which generate for every run a string output (loop size index is changing depends on how much files are in the directory). How can I concatenate the string output to another string vertically/send them into char/etc so I can save the final output (all the string output results) to a one text file?
Any idea is welcome.
Thanks.
0 件のコメント
回答 (2 件)
Azzi Abdelmalek
2012 年 10 月 16 日
s=[]
for k=1:10
s1=['text' num2str(k)]
s=strvcat(s,s1)
end
1 件のコメント
Matt J
2012 年 10 月 16 日
編集済み: Matt J
2012 年 10 月 16 日
Note - strvcat will eventually be removed from MATLAB. It is recommended in MATLAB documentation to use char instead. Also, it would be better to perform the concatenation after the loop (storing the strings in cells) so that s doesn't grow iteratively.
Matt J
2012 年 10 月 16 日
Assuming you've read the strings into a cell array you can use CHAR to concatenate them, e.g.,
>> char({'car','apple'})
ans =
car
apple
2 件のコメント
参考
カテゴリ
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!