Want to convert .MAT to .TXT

3 visualizaciones (últimos 30 días)
Sara
Sara el 20 de En. de 2017
Editada: Jorge Mario Guerra González el 20 de En. de 2017
Hello, I have multiple .MAT structures with multiple variable names and long vectors (3000+ of data) that I would like to process such that the data is put into a .TXT file with the variable names as the column header. EX: (i.e. X=[1.90,2.3] , Y=[2.5467,10.87], Z=[3.134,100.98]. So X, Y, Z are the column headers and the data fall underneath each respective column with the DECIMAL places properly aligned on top of each other.
Question:
I there a script that can do what I need?
Please help
Thank you
Sara

Respuestas (2)

Adam
Adam el 20 de En. de 2017
doc fprintf
should be able to do what you want, but you'll have to put together the format specification yourself and work out how to get decimal places lined up. This isn't usually something that is important in a text file for raw data.

Jorge Mario Guerra González
Jorge Mario Guerra González el 20 de En. de 2017
Editada: Jorge Mario Guerra González el 20 de En. de 2017
Here is quick way to do that. Using fprint as @Adam says. (This writes with 5 decimal places)
X=[1.90; 2.3]; Y=[2.5467;10.87]; Z=[3.134;100.98];
fid = fopen('example.txt','wt');
fprintf(fid, '%s\t %s\t %s\n', 'X','Y','Z');
fprintf(fid,'%0.5f\t %0.5f\t %0.5f\n',[X Y Z]);
fclose(fid);
You can import it with the headers to excel or whatever.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by