Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to read an n-dimensioned matrix from a binary file
Replies: 2   Last Post: Feb 13, 2013 1:00 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 7,881
Registered: 6/7/07
Re: How to read an n-dimensioned matrix from a binary file
Posted: Feb 13, 2013 1:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/13/2013 9:54 AM, Jim wrote:
> I would like to write a Matlab script to read an N-dimensioned matrix
> created in Fortran. Specifically, the Fortran code wrote to a binary
> file using the following:
>
> write(30) a, b, c
> with the following declarations for a,b,c
>
> real a(16,20,22,6,3, 2)
>
> real b(16,20,22,6,3,13)
>
> real c(16,20,22,6,3,13)
>
> In Matlab, it seems that fread handles only a vector or 2-dimesional matrix
> fread(fileID, sizeA) where sizeA is a vector of size n or 2-dimensional
> matrix [m,n].
>
> How can I read the N-dimensioned matrix I described?


Need more info...did the Fortran program write a Fortran unformatted
file as a default OPEN(lun,form='unformatted')? If so, there's a record
structure that will have to be dealt with (Fortran unformatted files are
_NOT_ C-like stream files but have internal record information to
support operations like BACKSPACE). You'll have to read that
information as well.

If, otoh, either a pre-F2003 extension was used (supported by every
compiler I'm aware of in one form or another) or the F2003+ Standard
mechanism has been implemented in the compiler and used, then all you
need to do is to read the file and reshape since both Fortran and Matlab
use column-major storage order.

--



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.