|
From: us on 19 Jun 2008 05:16 Jam: <SNIP reading a mixed type binary... it's easy and it's done all the time... however, it all depends on the anatomy of your file, eg, - the header: known length - are there predefined positions (including data types) in your file where you can look up stuff like: size of the header start position of the data block size of the data block and so on... us
From: Rune Allnor on 19 Jun 2008 05:55 On 19 Jun, 06:25, Jam <sramanuja...(a)gmail.com> wrote: > i > don't know how to read both text and binary data in matlab, At the lowest level of implementation the key is to treat the file as a binary file and the text as binary data. To extract a block of text from a binary file, do something like this: [a,count]=fread(fid,N,'uchar'); t = char(a); A well-designed format specification will state that the file format has one block at the start where the size and data formats are stated in the specification document. Start with reading that block. From there on different formats differ in that some formats continue with blocks of pre-determined sizes that are listed in the specification document, whereas other formats have blocks with dynamic sizes where you need to parse block headers internal to the file to learn the size of the next block. The process goes more or less as follows: 1) Read the next block, which size is known either from format specs or from previously parsed file contents. 2) Parse the new block for data and info. 3) Store the info and/or data contents as required. 4) Use presently known info (available from format specs or previousli parsed file contents) to find out the size of the next block to be read. 5) Repeat from 1). These sorts of things are huge jigsaw puzzles, just deal with one detail at the time and make sure to incorporate verification tests and data validators into your code. Rune
|
Pages: 1 Prev: Order of convolution and multiplying Next: how to declare variables with predefined size |