필터 지우기
필터 지우기

how to read bytes using fread or in a matrix

조회 수: 2 (최근 30일)
kumar panduga
kumar panduga 2016년 4월 30일
답변: Walter Roberson 2016년 4월 30일
I am using fread to open'.dat' files. The file has variables with its values displayed in matrix. Every column in assigned a variable and each column is of different length(1st column 4 bytes, 2nd column 2 bytes etc) I have tried opening 1st column but unable to open 2nd column. I would like to know how to all columns.
  댓글 수: 1
dpb
dpb 2016년 4월 30일
Need detailed description of file format. Sounds more like ASCII file from the above rather than stream (unformatted) file. And, files are record-oriented, not by column.

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 30일
collength = [4, 2, ... etc];
fmt = sprintf('%%%ds', collength);
fid = fopen('MyFile.dat', 'r');
datacell = textscan(fid, fmt, 'Delimiter', '', 'Whitespace', '');
fclose(fid);
Now datacell{K} is the K'th column as a cell array of strings.
I did not attempt to convert to numeric because you gave us no information that would suggest the columns are numeric. It might be appropriate to use %%%df or %%%dd

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by