필터 지우기
필터 지우기

How to read .dat file using fopen??

조회 수: 8 (최근 30일)
Vishnu Dhakad
Vishnu Dhakad 2018년 6월 11일
댓글: Walter Roberson 2018년 6월 12일
I want to read a .dat using following code but I am not getting any data.
there is not allowed to upload .dat file so i uploaded in a text file fomate.
fbc = fopen('AE33.dat');
BC = fscanf(fbc, '%.f-%f-%.f,%.f:%.f:%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f,%.f');
fclose(fbc);
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 6월 11일
(Note: you can zip .dat files and upload the zip)
Vishnu Dhakad
Vishnu Dhakad 2018년 6월 11일
편집: Vishnu Dhakad 2018년 6월 11일
Thanks,
Now,
I have attached it

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 11일
fmt = ['%{YYYY/MM/dd}D %{HH:mm:ss}D', repmat('%f', 1, 71)];
fbc = fopen('AE33.dat', 'rt', 'n', 'UTF8');
BC = textscan(fbc, fmt, 'HeaderLines', 7, 'CollectOutput', true);
fclose(fbc);
dt = BC{1}+(BC{2}-dateshift(BC{2},'start','day'));
dt.Format = 'default';
numbers = BC{3};
Now dt is a vector of datetimes read in from the first two columns of the lines, and numbers is a numeric array with 71 columns representing the data on each line after the date/time entries.
  댓글 수: 3
Vishnu Dhakad
Vishnu Dhakad 2018년 6월 12일
Can you explain to me that why you use 'UTF8'?
Walter Roberson
Walter Roberson 2018년 6월 12일
When I had a look at the content of your file, I saw that before the first few readable text characters, there were a couple of non-printable characters, which I recognized as being UTF Byte Order Mark that indicated UTF encoding was being used and which UTF was being used. I ran an old program of mine that analyzes UTF encoded files and it told me that the file was plain UTF-8.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by