フィルターのクリア

How do I write out mixed data to binary file without looping?

5 ビュー (過去 30 日間)
Justin Solomon
Justin Solomon 2014 年 6 月 26 日
コメント済み: Justin Solomon 2014 年 6 月 26 日
I have a matrix of data I need to write out to a binary file. Each column needs to be written out with a different precision, but I need to write it out in a specific order, such that values of different precisions follow each other. For example: int8 real*4 int8 real*4 ...
Is is possible to do this without looping? [Maybe some combination of using the 'skip' option with fwrite() along with the fseek()?]
Thanks in advance for any insights. Justin

回答 (1 件)

Image Analyst
Image Analyst 2014 年 6 月 26 日
Just use fwrite() to write out data of the proper class. You can write out all columns in a single fwrite() if there are not too many of them, otherwise put it in a loop. Don't be afraid of loops
fwrite(fid, '%d%f%d%f', uint8Var1, single1, uint8Var2, single2);
fwrite(fid, '%f', singleArrayOf1000elements);
  1 件のコメント
Justin Solomon
Justin Solomon 2014 年 6 月 26 日
Thanks for the suggestion. However, I don't think the syntax you show works. From the help menu, the syntax is fwrite(fileID, A, precision). Thus fwrite() is expecting the fid, then the values to be written, and then the precision to use. The syntax you described looks like it would work if I were writing to a text file with fprintf().

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by