comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » reading .mat files in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
reading .mat files in IDL [message #50505] Thu, 05 October 2006 03:30 Go to next message
Ulan is currently offline  Ulan
Messages: 8
Registered: April 2005
Junior Member
Dear all,

Recently I had to tranfer some time series plots from Matlab (.mat
files) into IDL. I have used IDL's "Binary Import" macro and had a few
problems. I thought, the problems were due to the data type
miscommunication: when the double data type in Matlab was imported as
double into IDL the data range was somewhat different (looked rather
streched like in BYTSCL command). I have expieremented with other data
types in Matlab (int8, int16, int32) but then IDL's binary template
complaint of improper data sizes. Finally, I had to make 2D array of my
time-series in Matlab, copy array cells into Notepad and save it as an
ASCII. I guess it is not the proper way of transfering data and most
likely I'll face the same problem when transfering larger 2D or 3D
data... I searched the forum for the same topics but couldn't find an
answer. Also a link on one site of 'reading .mat files into IDL' was
broken. So, if anybody had expierence ...

Regards,
Ulan
Re: reading .mat files in IDL [message #50630 is a reply to message #50505] Fri, 06 October 2006 07:50 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
Ulan wrote:

> Dear all,
>
> Recently I had to tranfer some time series plots from Matlab (.mat
> files) into IDL. I have used IDL's "Binary Import" macro and had a few
> problems. I thought, the problems were due to the data type
> miscommunication: when the double data type in Matlab was imported as
> double into IDL the data range was somewhat different (looked rather
> streched like in BYTSCL command). I have expieremented with other data
> types in Matlab (int8, int16, int32) but then IDL's binary template
> complaint of improper data sizes. Finally, I had to make 2D array of my
> time-series in Matlab, copy array cells into Notepad and save it as an
> ASCII. I guess it is not the proper way of transfering data and most
> likely I'll face the same problem when transfering larger 2D or 3D
> data... I searched the forum for the same topics but couldn't find an
> answer. Also a link on one site of 'reading .mat files into IDL' was
> broken. So, if anybody had expierence ...
>
> Regards,
> Ulan

Can you tell us more about what you have actually written into your data files?

A .mat file is not a trivial item. If you look in your documentation tree for
MATLAB you will find a document which describes the contents of the .mat files
- it is 41 pages long. Attempting to implement a reader for those files is not
trivial.

It's unclear to me how IDL's "Binary Import" macro could import a MATLAB .mat
file. A MATLAB data file consists of a very complex description of how the data
is stored, then there is the actual data which can be in several non-trivial
formats. Because of the nature of MATLAB variables the MATLAB V5 data format is
also recursive - cells and structures can each contain other cells and
structures... Unless you understand exactly how MATLAB has chosen to save your
data it's virtually impossible to read it with anything other than MATLAB. It
can be done, but not with a simple binary import.

The best way to export data to be read by other applications is to use a simple
binary write (fwrite). This limits the type of data you can export, but if it
can't be exported by fwrite there's a good chance that the external application
wouldn't understand the matrix type anyway (how would IDL interpret a MATLAB
structure?). After exporting in binary it should be trivial to import into IDL.
You may have to do some work transposing rows/columns as I believe MATLAB and
IDL have different ideas on whether a 2D array should be column-major or
row-major.

I did, many eons ago, have some IDL code which would load MATLAB V4 data files
into IDL. The V4 data file format is much, much simpler than the V5 format. I
think that it's still possible to write data in V4 format from MATLAB by using
the -v4 flag to the save command (at least, I think that's how you do it, it's
some time since I even ran MATLAB...).

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
Re: reading .mat files in IDL [message #50634 is a reply to message #50505] Fri, 06 October 2006 06:41 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Ulan wrote:
> Dear all,
>
> Recently I had to tranfer some time series plots from Matlab (.mat
> files) into IDL. I have used IDL's "Binary Import" macro and had a few
> problems. I thought, the problems were due to the data type
> miscommunication: when the double data type in Matlab was imported as
> double into IDL the data range was somewhat different (looked rather
> streched like in BYTSCL command). I have expieremented with other data
> types in Matlab (int8, int16, int32) but then IDL's binary template
> complaint of improper data sizes. Finally, I had to make 2D array of my
> time-series in Matlab, copy array cells into Notepad and save it as an
> ASCII. I guess it is not the proper way of transfering data and most
> likely I'll face the same problem when transfering larger 2D or 3D
> data... I searched the forum for the same topics but couldn't find an
> answer. Also a link on one site of 'reading .mat files into IDL' was
> broken. So, if anybody had expierence ...
>

Hi,

I don't have a solution for reading MAT files directly into IDL, but a
while back (a long while now) Nick Wolf and I cobbled together a set of
IDL and MatLab routines to exchange data via file I/O. Send me an email
if you would like it.

Cheers,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: wrapper functions
Next Topic: input expression as a variable.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:36:37 PDT 2025

Total time taken to generate the page: 0.00572 seconds