How to read and store binary data from a file and store it into the MATLAB in row major using fread function?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 20 Jun. 2017
Beantwortet: MathWorks Support Team
am 30 Jun. 2017
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
Akzeptierte Antwort
MathWorks Support Team
am 20 Jun. 2017
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!