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,944
Registered: 12/7/04
Re: trouble saving data structure to a file
Posted: Nov 12, 2012 10:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Ben " <ben-walker@northwestern.edu> wrote in message
news:k7j98m$bnk$1@newscl01ah.mathworks.com...
>> 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.

>
> It seems like you could approach this a few different ways. First, like
> you say, if SAVE could figure out the '.' notation, then allow
> 'struct.field' storage, requiring a new '-structindex' flag even, but not
> any of the other strings that would need to be evaluated.
> Another way is to leave the behavior as is (only allowing storing of
> direct variables). But a third way is to allow storing of data, but not
> storing of _creation_ of data. Sin(A) "creates" data in the sense that it
> has to allocate new memory to store new data. Whereas struct.field or
> A(2:3,5:7) is accessing data that already exists.


We could. As far as I can remember this is the first request I've seen for
this functionality. If you feel strongly that SAVE should recognize
expressions and not just variable names, please submit a formal enhancement
request for that functionality through Technical Support. When you do,
please mention your usage that started this thread as motivation.
Development takes into account whether an enhancement request comes from a
user as one factor when deciding what features to implement.

>> But what should the variable in the MAT-file generated by this call be
>> named?
>>
>> 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.
>>

>
> What's wrong with calling the data 'ans' in the .mat file?


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

Granted this is somewhat of an unusual scenario, but if we did decide to
implement this functionality this way I guarantee you someone would try to
use it this way eventually.

> If the user doesn't want to name the variable, then they should at least
> have the foresight to give a good file name:
>
> A = magic(10);
> save('Magic10Values_23_57'),'A(2:3, 5:7)');


--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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.