How can I combine two text files having different columns in one file?

 Respuesta aceptada

a=dlmread('a.txt');
b=dlmread('b.txt');
c=[a,b];
dlmwrite('c.txt',c);

2 comentarios

a=dlmread('a.txt')
b=dlmread('b.txt')
header=' x y z'
c=[a b]
fid=fopen('file.txt','w')
fprintf(fid,'%s \r\n',header)
myformat='%12.8f %12.8f %12.8f \r\n'
fprintf(fid,myformat,c)
fclose(fid)
Sorry it writes just one columns three times in the last file ?

Iniciar sesión para comentar.

Más respuestas (1)

c=[textread('a.txt') textread('b.txt')];

2 comentarios

ND
ND el 19 de Jun. de 2015
Editada: ND el 19 de Jun. de 2015
Dear Azzi,
After combining them I have added headers for them, now I should import these data to excel spreadsheet but it is failed? Many thanks
Stephen23
Stephen23 el 19 de Jun. de 2015
Editada: Stephen23 el 19 de Jun. de 2015
Similarly to dpb's answer you can also use load:
>> c = [load('a.txt'),load('b.txt')];

Iniciar sesión para comentar.

Etiquetas

Preguntada:

ND
el 19 de Jun. de 2015

Comentada:

ND
el 19 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by