writing binary data with matlab !
Show older comments
I want to write some values in a binary format so that I can open in a specific software. I want to write it after skipping certain byte (c ) .After that what I wanted to do is write matrix A, B and C which are row vectors of equal size so that follows a1 b1 c1 a2 b2 c2 pattern ! Each data in the matrix is of size 4 bytes. Here what I did !
fid = fopen(test.bin,'wb')
fseek(fid, c, 'bof');
% fwrite use column order while writing therefore I used transpose of A
% skip is 8 because to keep empty 8 bytes which will take by B and C
fwrite(fid,A','int32','ieee-le',8);
fseek(fid, c+4, 'bof');
fwrite(fid,B','int32','ieee-le',8);
fseek(fid, c+8, 'bof');
fwrite(fid,C','int32','ieee-le',8);
fclose(fid);
Is this a correct way to do ? Anybody has any idea?? When I try to get data from the binary file to check if the data has been properly written! I couldnot retrieve matrix A, B and C
fid = fopen('A.bin','rb') %open file
fseek(fid, c, 'bof');
data_A = fread(fid, inf, 'int32',8);
fseek(fid, c+4, 'bof');
data_B = fread(fid, inf, 'int32',8);
fseek(fid, c+8, 'bof');
data_C = fread(fid, inf, 'int32',8);
fclose(fid);
The output of data_A, data_B, data_C should same as original matrix A, B, C. In my case it is not ? what I am doing wrong ! Sukuchha?
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!