How to open and write into a .byt file?
3 views (last 30 days)
Show older comments
Srijith Rajeev
on 3 Jul 2015
Commented: Walter Roberson
on 4 Jul 2015
Hello all, I have a code which has .byt file. Was hoping any of the users here know how to write data into a .byt file. Thank you
4 Comments
Accepted Answer
Walter Roberson
on 4 Jul 2015
datasetname = 'Tree84vq'; %ie if we are working with Tree84vqX.byt
newsuff = '_new'; %adjust to differentiate old file and new file
Xsuff = 'X.byt';
Ysuff = 'Y.byt';
Zsuff = 'Z.byt';
Xfilename = [datasetname Xsuff];
Yfilename = [datasetname Ysuff];
Zfilename = [datasetname Zsuff];
newXfilename = [datasetname newsuff Xsuff];
newYfilename = [datasetname newsuff Ysuff];
newZfilename = [datasetname newsuff Zsuff];
fid = fopen(Xfilename, 'r');
Xdata = fread(fid, inf, 'single');
fclose(fid);
fid = fopen(Yfilename, 'r');
Ydata = fread(fid, inf, 'single');
fclose(fid);
fid = fopen(Zfilename, 'r');
Zdata = fread(fid, inf, 'single');
fclose(fid);
now manipulate Xdata, Ydata, Zdata to make newXdata, newYdata newZdata
fid = fopen(newXfilename, 'w');
fwrite(fid, newXdata(:), 'single');
fclose(fid);
fid = fopen(newYfilename ,'w');
fwrite(fid, newYdata(:), 'single');
fclose(fid);
fid = fopen(newZfilename, 'w');
fwrite(fid, newZdata(:), 'single');
fclose(fid);
You might have noticed that I output to a different file name than was used for input. I always advise against overwriting existing files unless you are certain you have a backup. Especially until the code is fully tested.
2 Comments
Walter Roberson
on 4 Jul 2015
Yes. .byt format is a list of single precision numbers in binary with no headers. That is what I read in and write out.
More Answers (0)
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!