How to read and store binary data from a file and store it into the MATLAB in row major using fread function?

2 ビュー (過去 30 日間)
I'd like to read in the binary file and generate 2 columns of data as shown in the text file.
The binary data consists of 16 bit signed integers from two channels of A/D data. The samples in the binary file alternate by channels, and it would be nice to turn the data into an array of two columns for the two channels.
For example consider a file contains following data:
1 2 3 4 5 6 7 8
 I would like to read data as:
1     2
3     4
5     6
7     8

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 6 月 20 日
MATLAB always stores data into column major. But as workaround to this issue you can read the file as 2 rows and multiple columns and transpose the matrix to get expected result.
For example the file can be read as:
fileID = fopen('test1.bin');
A = fread(fileID,[2 inf],'int16');
B = transpose(A);
fclose(fileID);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by