Saved data from Matlab gets corrupted?

6 ビュー (過去 30 日間)
Ken
Ken 2013 年 6 月 30 日
Hello to everyone,
I have a code in ".mfile" which generates a 1X14240 data. The output data is composed of complex numbers, which all appear well at the command line. However, whenever I write the data into either a ".dat", or ".txt" file, I find it all corrupted by the time I open it up. What could be possibly wrong with it? Could it be that the data length is too long?.
Here is the code I used for saving the file:
filename='filename.txt';
fid = fopen(filename,'w');
newshape = reshape([real(data);imag(data)],1,2*length(data));
F = fwrite(fid,newshape,'float');
fclose all;
Thanks for your anticipated responses
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 6 月 30 日
To check: you do know that fwrite() is to write binary data? So even though you named your file with .txt, the file will not have the numbers in readable form?

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

採用された回答

Guru
Guru 2013 年 7 月 3 日
編集済み: Guru 2013 年 7 月 3 日
The reason why it's wrong is explained by Walter Roberson.
What you can do to probably get your intended result is to use
fprintf
instead of
fwrite
Then you can write your data to the file in text format instead of binary format.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by