How to read and store binary data from a file and store it into the MATLAB in row major using fread function?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 20 de Jun. de 2017
Respondida: MathWorks Support Team
el 30 de Jun. de 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
Respuesta aceptada
MathWorks Support Team
el 20 de Jun. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!