Monday, December 12, 2011

Read text and binary data in matlab?

i would like to read the data from a file in matlab. the details of the file is as below.





the first few lines contains data in text format (header section), which act as descriptors for the data which follows these lines.





the remaining lines contains data in binary format, which is specified according to the format given in header section.





my problem is i want to load the file in matlab, read the header section and define the variables, then continue to read the binary data in accordance with the header descriptions.





for the sake of understanding, i deleted the text format and used the following script to read the raw binary data.


fid=fopen('c:\test.bin');


h=fread(fid,1000);


and am able to view the output by typing h(:) in command window. but i don't know how to read both text and binary data in matlab, and associate the link between them. can anyone explain me how to do this? it will be more helpful if you can explain with a script in matlab as example.|||Matlab has several c-like functions for reading text. See the help files for fgetl (which gets all characters up to the first newline), as well as fscanf (similar to c version, gets a formatted sequence of tokens). For example, you could read the text part of the header one line at a time, and then parse each line using sscanf or regexp. Or you could read the header data directly using fscanf, depending on the format. After parsing the header, you can then read the binary portion of the file using fread as in your example.





Unfortunately you didn't give an example of the header's exact format, so I can't provide specific code to read it.

No comments:

Post a Comment