How to read a custom file with data, and search and parse
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to read files with a custom format, where I need (lack of better word) the raw data of the file so I can search and parse it. So far I am doing trying with fopen and fread to get the data.
fileID = fopen('myfile.customformat');
binaryString = fread(fileID);
So the files I need to parse have a header with a string (4 bytes) followed by uint32 containing the size of the following subsequent data. The data of interest, you could say, is an array of data sets, all with their own header string (4 bytes), and size (uint32) for all the points in one set. Essentially I just need to search for the header for each data set and extract the data, but the way I am reading the data right now with fread, I get the data in an array of dec, which does not seem that well to parse e.g. searching for the header strings.
What approach should I take instead? Below is, hopefully, a better overview of the data structure in the file.
Example of the data structure
- file header (string, 4 bytes)
- size of data package (uint32, 4 bytes)
- .. random irrelevant data
- dataset1_header (string, 4 bytes )
- dataset1_size (uint32, 4 bytes)
- dataset1_data (20x float)
- dataset2_header (string, 4 bytes )
- dataset2_size (uint32, 4 bytes)
- dataset2_data (20x float)
0 comentarios
Respuestas (1)
Dave Behera
el 4 de Abr. de 2016
fread is used to read from a binary file. Can you try using fscanf and fileread?
1 comentario
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!