Want to convert .MAT to .TXT
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Adam
on 20 Jan 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.
0 Comments
Jorge Mario Guerra González
on 20 Jan 2017
Edited: Jorge Mario Guerra González
on 20 Jan 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.
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!