fopen for multiple binary files

I have to read Binary files in matlab , I have used following codes to open file
file='D:\.....cmorph\CMORPH_V1.0_ADJ_0.25deg-DLY_00Z_20090620';
a=fopen(file);
b=fread(a,'float');
day1=reshape(b,1440,480);
It works and I have output of day1 is matrix 1440x480x1.
Now I want to open and read all binary file of folder (365 files) to create the matrix of all days (1440x480x365).
How can I do that?

댓글 수: 5

Phan Duong
Phan Duong 2019년 6월 17일
Thank you
I change a little of bit and it works good
one more question
when I use sprintf, the name of file like that 'cm20010101', 'cm20010102' ...... 'cm20013012', 'cm20013112' and I use code below and I have error. How can I fix?
myfilename = sprintf('D:\\.....\\cm2001%4d', k); or
myfilename = sprintf('D:\\.....\\cm2001%2d%2d', k);
projectdir = 'D:\.....cmorph';
myfilename = fullfile(projectdir, sprintf('cm2001%04d', k))
I used this code
numfiles = 365;
mydata = cell(1, numfiles);
projectdir='D:\.....\2001';
for k = 1:numfiles
myfilename = fullfile(projectdir,sprintf('CMORPH_V1.0_ADJ_0.25deg-DLY_00Z_2001%04d', k));
mydata{k} = fread(fopen(myfilename),'float');
end
but I have error:
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
I check for each month, it still ok.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Holidays / Seasons에 대해 자세히 알아보기

태그

질문:

2019년 6월 17일

댓글:

2019년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by