from .mat to .txt

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!

回答 (3 件)

Jan
Jan 2011 年 6 月 6 日

5 投票

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 件のコメント

Wafia
Wafia 2011 年 6 月 7 日
Thank you Jan, this works fine, but sorry may be I don't know alot about Matlab, how to open this new file as a text? I've just tried and it doesn't work!
Titus Edelhofer
Titus Edelhofer 2011 年 6 月 7 日
Usually
edit FileName.txt
But depending on the size of the file, this might fail in MATLAB. Use any operating system editor to edit the file.
fateh
fateh 2014 年 10 月 31 日
this codes give symbol ',' between columns. Then, how could i replace ',' with blank space?
Yuanjun Zhao
Yuanjun Zhao 2017 年 6 月 5 日
Hi fateh, just make it like this dlmwrite('FileName.txt', Data.(DataField{1}), 'delimiter', ' ');
SUSHMA MB
SUSHMA MB 2017 年 7 月 27 日
How can i convert the .mat file into the following format of .txt file
x={
( 0.000000 0.000000 )
( 0.500000 0.333333 )
( 0.250000 0.666667 )
( 0.750000 0.111111 )
( 0.125000 0.444444 )
( 0.625000 0.777778 )
( 0.375000 0.222222 )
( 0.875000 0.555556 )
( 0.062500 0.888889 )
( 0.562500 0.037037 )
}
Jan
Jan 2017 年 7 月 27 日
編集済み: Jan 2017 年 7 月 27 日
@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.

サインインしてコメントする。

Fangjun Jiang
Fangjun Jiang 2011 年 6 月 6 日

0 投票

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 2014 年 10 月 31 日

0 投票

As of R2014a, you can also use saveVariablesToScript

カテゴリ

ヘルプ センター および File ExchangeData Import and Analysis についてさらに検索

タグ

質問済み:

2011 年 6 月 6 日

編集済み:

Jan
2017 年 7 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by