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: trouble saving data structure to a file
Replies: 7   Last Post: Nov 12, 2012 10:21 AM

Advanced Search

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

Posts: 17,945
Registered: 12/7/04
Re: trouble saving data structure to a file
Posted: Nov 9, 2012 10:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Ben Ruppel" <brspam@cox.net> wrote in message
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <k7b9r0$ahr$1@newscl01ah.mathworks.com>...


> Hi Steve,
> Thank you for the information and the useful links. While I accept it as
> the truth, I still think it's a little odd and inconsistent that some
> functions aren't smart enough to figure out when an expression points to a
> variable.

For this particular syntax, SAVE probably could handle the expression (since
you used the '-struct' flag) and generate variables with reasonable names in
the MAT-file.

But what should the variable in the MAT-file generated by this call be

save('myfile.mat', 'sin(A)')

Okay, SIN is a function and that expression is more complicated than your
simple attempt to index into handles with the dot-notation. Fair enough.
Let's take another indexing example, though. What should the name of the
variable in the MAT-file created by this SAVE call be?

A = magic(10);
save('myfile.mat', 'A(2:3, 5:7)')

Calling it A would be misleading. I suppose we could pass that expression
through GENVARNAME but the generated variable name is kind of long and
that's a fairly simple example.

> After all, if I were to create my own function, I could pass in a variable
> name or a data structure member reference / expression and the function
> would see both as the data that is being referenced. Oh well.

There's a difference between the _data_ in a variable or returned by an
expression and the _name_ of a variable. SAVE does not accept the _data_ as
input, it accepts the _name_. Two other functions that accept names not data
are EXIST and WHOS. They have similar behavior to SAVE.

A = magic(10);
exist('A(5, 5)', 'var') % returns false even though A has an element (5, 5)
whos('A(5, 5)') % Does not display anything

On the other hand, functions like SIN accept the _data_, and they're
perfectly happy to accept the result of an expression.

sin(A(5, 5)) % sin(9)

Steve Lord
To contact Technical Support use the Contact Us link on

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

[Privacy Policy] [Terms of Use]

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