How can I convert a .mat file into a .txt file with all the headers? I do not know how many fields are present.

How do I export this data? I have MATLAB.

I tried in MATLAB:

load('test_data.mat'); 
save('test_data.txt', '-ascii'); 

It did not work.

link|improve this question
Your original question was moved to superuser.something by people who think that it was not programming related. They have a point, your question does not require even basic programming skill to answer, it is purely a matter of using Matlab. It boggles my mind that you have Matlab and can't either read a mat file or write a text file in the format you require. Have you read the documentation ? If you have, what have you tried so far ? While you think about it, I'm voting to close. To stop this process, turn this into a programming question and provide evidence that you are trying. – High Performance Mark Jul 14 '10 at 19:53
@ Mark :If u do not wanna help , atleast do not stop others from helping me. its a ASCII file and headers and somehow its not importing in matlab so i wanted to know what is the command. – Paul Jul 14 '10 at 20:09
2  
Your question is unclear, since you really don't tell us what could be in your .mat file and what you want it to look like in the .txt file. If you take a variable stored in a .mat file and save that to a new file as ASCII text, there will be no variable name associated with the data. The raw data will simply be dumped to the ASCII file. Do you have multiple variables from the .mat file that you want in the .txt file? How do you want the .txt file formatted? How should we display data from multiple variables in the .txt file? – gnovice Jul 14 '10 at 20:31
feedback

migrated from stackoverflow.com Jul 14 '10 at 21:07

This question came from our site for professional and enthusiast programmers.

3 Answers

If you are using MATLAB you can simply execute the command

load 'file.mat'

which will load all the variables in the .mat file into your workspace. You can then do something like:

save('newfile.txt', 'var1, 'var2', ..., '-ascii')

to save the variables you specify into an ASCII file. The save() function has a lot of arguments and options, check the documentation.

And if you are not using MATLAB your question doesn't make much sense to me.

link|improve this answer
feedback

It depends on what's in your .mat file. If it's a matrix, you could export the matrix stored in your file to the widely used CSV format.

link|improve this answer
1  
how do i do it? when i try 2 rename it gives me useless stuff – Paul Jul 14 '10 at 19:45
Try to rename it to .ascii instead of .txt – Mikhail Jul 14 '10 at 20:36
All joking aside use load() and dlmwrite(), help here mathworks.com/access/helpdesk/help/techdoc/ref/load.html and here mathworks.com/access/helpdesk/help/techdoc/ref/dlmwrite.html – Mikhail Jul 14 '10 at 20:41
feedback

https://sourceforge.net/projects/matio/

link|improve this answer
-1: this is a very roundabout way of reading a mat file into Matlab. – High Performance Mark Jul 14 '10 at 17:55
feedback

Your Answer

 
or
required, but never shown