How to open and write into a .byt file?

3 vues (au cours des 30 derniers jours)
Srijith Rajeev
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
  4 commentaires
Walter Roberson
Walter Roberson le 4 Juil 2015
Srijith Rajeev
Srijith Rajeev le 4 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by