fwrite a matrix by chunks at a time

조회 수: 1 (최근 30일)
Pierre-Pascal
Pierre-Pascal 2011년 8월 24일
hi I am doing some fancier file writing and need to write in a file a matrix, say A=[1:10000]and save it by chunks of 512 datapoints in int16 format. I also need to skip 20bytes in between I am trying fwrite(fid,A,'512*int16',20) but I keep getting a bunch of zeros. ultimately I will use, to read it, a command like fread(fid,512*N,'512*int16=>int16',20); Am I in the correct direction? there is a very small help file for fread.

답변 (1개)

Jan
Jan 2011년 8월 25일
After some tests I have the impression that:
fwrite(fid, A, '512*int16', 20)
inserts the 20 bytes for skipping before the blocks, while:
fread(fid, 512*N, '512*int16=>int16', 20)
skips the 20 bytes behind the block. Where do you want the skipping bytes? If before the data blocks is wanted, modify the reading like this:
fread(fid, 20, 'int8'); % Skip manually at first
fread(fid, 512*N, '512*int16=>int16', 20)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by