Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: importing mat format doesn't import variable names

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53543] Re: [mg53511] Re: importing mat format doesn't import variable names
  • From: Yasvir Tesiram <tesiramy at omrf.ouhsc.edu>
  • Date: Sun, 16 Jan 2005 22:24:00 -0500 (EST)
  • References: <200501130812.DAA03781@smc.vnet.net> <cs8kid$ejl$1@smc.vnet.net> <200501150644.BAA25331@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
I may be misintepreting you but it seems that you want to export a "List"
of matrices. So instead of exporting in the MAT format why don't you try
List or Table as export formats.
If however, you want to use the data in some external program that relies
on a .MAT extension to recognise the file, then you will also need to know
the structure and encoding method of the file. As a simple test, export
one small matrix in MAT format and open it with a text editor.
Here is a suggestion following from your original post;

aa = "aa = " <> ToString[{{2, 3}}]
bb = "bb = " <> ToString[{{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}]
cc = {aa, bb}

Export["~/Desktop/testfile", cc, "Table"]

Import["~/Desktop/testfile", "Table"] // TableForm

Also have a look at OpenWrite and OpenAppend, OpenRead and related
functions. Often when writing and reading files to and from disk, these
are more appropriate, particulalry when you have to work with proprietry
formatted files that aren't commonplace.
Cheers
Yas

On Sat, 15 Jan 2005, Ben Barrowes wrote:

> It seems that Import extracts only numerical data and loses the variable
> names from MAT files.
>
> OK, how about an Export problem?
>
> Let's say I have two arrays:
> aa={2,3}
> and
> bb={{9,8,7},{6,5,4},{3,2,1}}
>
> How can I save both of these to a MAT file?
>
> I can save either one, e.g.:
> Export["filename",aa,"MAT"];
>
> But if I try to:
> Export["filename",{aa,bb},"MAT"];
>
> The resulting file size is 0 and the Import consequently fails.
>
> Any way to export more than one matrix to a MAT file?
>
>
> What I would really like to do is save all the currently defined
> variables to a MAT file. I tried:
>
> Export["filename",ToExpression[Names["`*"]],"MAT"];
>
> But that fails in the same way as the preceeding example when there is
> more than one variable defined.
>
>
>
> Tomas Garza wrote:
> > Could you give us a small example of the file you're trying to import
> > (perhaps 3 x 3), including the variable names?
> >
> > Tomas Garza
> > Mexico City
> > ----- Original Message -----
> > From: "Ben Barrowes" <barrowes at alum.mit.edu>
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> > Subject: [mg53543] [mg53511]  importing mat format doesn't import variable names
> >
> >
> >
> >>This is a very responsive ng. Thanks!
> >>
> >>When I Import["file","MAT"] files, the variable name information is
> >>lost. Is this the normal behavior? Or is there a switch I can specify to
> >>import the variable names as well?
> >>
> >>For example, if file.mat has two variables, foo (3x3) and bar (3x3), and
> >>I Import it, all I get is 1 nested List for a result.
> >>{{{foo[[1,1]],foo[[1,2]],foo[[1,3]]},...},{{bar[[1,1]],...}}}
> >>However, they are simply numbers with no names associated with the list.
> >>
> >>I know I could do:
> >>{foo,bar}=Import["file.mat","MAT"];
> >>
> >>but I was wondering if there was a way to Import variable names without
> >>specifying them explicitly. The information is in the .mat file. Why
> >>doesn't Mathematica extract it?
> >>
> >>Similarly, when I Export a matrix into a mat file, will the variable
> >>name be lost?
> >>
> >>Ben Barrowes
> >>
> >>
> >
> >
> >
>


  • Prev by Date: Re: Mathematica Graphics output in an ASP.NET WebApplication
  • Next by Date: Re: Colored Surface
  • Previous by thread: Re: importing mat format doesn't import variable names
  • Next by thread: Re: importing mat format doesn't import variable names