How to read a custom file with data, and search and parse
10 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Dave Behera
2016 年 4 月 4 日
fread is used to read from a binary file. Can you try using fscanf and fileread?
参考
カテゴリ
Help Center および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!