How can open and read .dat file?

470 ビュー (過去 30 日間)
SM
SM 2020 年 9 月 8 日
コメント済み: Walter Roberson 2020 年 11 月 4 日
A=[3 4 4 NaN NaN NaN NaN NaN;
36 46 4 4 1 3 NaN NaN;
24 32 3 3 1 3 2 3;
25 32 3 3 1 3 2 NaN];
I have stored this matrix as a .dat file using following code:
filename = sprintf('output.dat');
dlmwrite(filename, A, ' ' );
Now I want to open (fopen) this "output.dat" file in read mode and want to read data from this open file using fscanf. How can I do that?
any help would be greatly appreciated.
Thank you!
  2 件のコメント
Rik
Rik 2020 年 9 月 8 日
What did you try?
SM
SM 2020 年 9 月 8 日
The matrix A has been stored in output.dat file in my computer. Now I want to read data from the output.dat file using fopen and fscanf. I have used the following code:
fileID = fopen('output.dat','r');
result = fscanf(fileID,'%f')
It results single column array but I need the output in the following format:
result=[3 4 4 NaN NaN NaN NaN NaN;
36 46 4 4 1 3 NaN NaN;
24 32 3 3 1 3 2 3;
25 32 3 3 1 3 2 NaN];
or,
result=result={[3 4 4]; [36 46 4 4 1 3]; [24 32 3 3 1 3 2 3]; [25 32 3 3 1 3 2]};

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

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 8 日
result = load('output.dat');
  4 件のコメント
Huy Le Van
Huy Le Van 2020 年 11 月 4 日
編集済み: Rik 2020 年 11 月 4 日
I can not read file.dat.
Do you replay follow email []@gamil.com
Walter Roberson
Walter Roberson 2020 年 11 月 4 日
dat is not a fixed file format. It is used by many different programs for whatever data they have handy. You would need to know which program created the file to try to figure out what the file format is.

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

カテゴリ

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