How to open and write into a .byt file?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Srijith Rajeev
le 3 Juil 2015
Commenté : Walter Roberson
le 4 Juil 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
Réponse acceptée
Walter Roberson
le 4 Juil 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 commentaires
Walter Roberson
le 4 Juil 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Low-Level File I/O dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!