How to concatenate in a loop?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Ken Atwell
el 10 de Ag. de 2013
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 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!