from .mat to .txt

486 views (last 30 days)
Wafia
Wafia on 6 Jun 2011
Edited: Jan on 27 Jul 2017
Hello, my question is simple and please I request a simple answer, How to convert a big table of data .mat to a text file preserving the same size? I can't give names of variables it's just a matrix full of numbers, the size is bigger than 1000, Thanks in advance!

Answers (3)

Jan
Jan on 6 Jun 2011
The question is a little bit vague. I guess, you want something like this:
Data = load('FileName.mat');
DataField = fieldnames(Data);
dlmwrite('FileName.txt', Data.(DataField{1}));
  6 Comments
Jan
Jan on 27 Jul 2017
@SUSHMA MB: Please do not append new questions as comment to answers of a different question. Open a new thread instead. Note that the readers cannot know, what "the .mat file" is.
Most likely the answer will be easy:
data = rand(10, 2); % Perhaps this is the contents of the MAT file
fid = fopen(FileName, 'w');
if fid==-1, error('Cannot open file: %s', FileName); end
fprintf(fid, 'x={\n');
fprintf(fid, '( %.6f %.6f )\n', data.');
fprintf(fid, '}\n');
fclose(fid);
Do you see the problem? Now you cannot accept the answer and further comments will confuse the readers, because it is unclear, if they concern the original or your question. Therefore such "thread-highjacking" is not wanted.

Sign in to comment.


Fangjun Jiang
Fangjun Jiang on 6 Jun 2011
Follow the related question that I asked. Save workspace to m-file. Basically use Simulink.saveVars if you have it.

Sean de Wolski
Sean de Wolski on 31 Oct 2014
As of R2014a, you can also use saveVariablesToScript

Tags

Community Treasure Hunt

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

Start Hunting!