How to open and write into a .byt file?

3 views (last 30 days)
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
Srijith Rajeev
Srijith Rajeev on 4 Jul 2015
@Walter: Yes it is. The project I am working on gives me MAT5 files beforehand and I wanted to stick to MATLAB if it was feasible.

Sign in to comment.

Accepted Answer

Walter Roberson
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
Srijith Rajeev
Srijith Rajeev on 4 Jul 2015
Thank you @Walter. I have a doubt though, will the new file being saved be in .byt format?
Walter Roberson
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.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!