Read in file that has raw binary image data and an XML footer

3 次查看(过去 30 天)
Hello, I need to read in data from a file that contains a large amount of raw binary image data (singles) followed by an XML footer. I can easily read in the image data (if I know the size of the array), but I'm not sure how to then proceed and read in the rest of the file in XML format. The xmlread() function needs a standalone XML file. My thought was to copy (bit by bit) the footer of the file into a temp file that would then be read by xmlread(). But I'm not quite sure how to do that copy just a part of a file into a new file. Any help would be much appreciated.
Justin

采纳的回答

Ken Atwell
Ken Atwell 2015-6-14
You've got the right idea.
Since you know the size of the image, open the mixed image/XML file with fopen, then use fseek to position the reader just after the image. Then use fread to read the tail of the file. Write this text to a temporary file.
  2 个评论
Justin Solomon
Justin Solomon 2015-6-14
Thanks for your response Ken. When I posted the question I hadn't realized that XML files are just human readable text files (I've never worked with XML before). I've implemented your suggestion and it seems to work well. The only thing that bugs me (from a purely "elegant code" perspective) is that I'm reading in the text, then writing it out again. Do you know of a way to tell Matlab to just carbon copy the bits from a range of read positions in File A, into a new File B?
Anyways, thanks again for your answer. I've got something that works so please don't spend any time thinking about the more "elegant" approach unless you know something off the top of your head.
Justin
Ken Atwell
Ken Atwell 2015-6-14
I'm not aware of any way to create a "file" that is a subset of another without actually copying the bits. xlmread takes a filename only and not a string or file handle and alternative sources of data, which would also eliminate the need for a temporary file.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile 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!

Translated by