How to concatenate in a loop?
1 回表示 (過去 30 日間)
古いコメントを表示
A='firstname_01';'firstname_02';'firstname_03' B='lastname_01';'lastname_02';'lastname_03'
A is a set of string in .txt file 1 and B is a set of string in .txt file 2. I need to concatenate the corresponding strings in both text files and put it in the excel sheet, such that the first cell should contain firstname_01lastname_01, second cell should contain firstname_02lastname_02 and so on. Is it possible to do so in Matlab?
0 件のコメント
回答 (2 件)
Ken Atwell
2013 年 8 月 10 日
You can import each file with code like the following:
lastnames = {};
f = fopen('B.txt');
while ~feof(f)
lastnames{end+1} = fgetl(f);
end
This will work fine for smallish files (hundreds of names), but the dynamic cell array growth will kill performance if you are working with large files. In this case, you will need to do something a bit more clever.
Once you have the two cell arrays (presumable of the same length), you can strcat them together. Then use xlswrite to emit.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!