From: StarkEffekt Heiles on
Hi MatlabCentral Members!

For one of my research projects I have to deal with big matrices which are generated in a for loop. Since my memory is limited I have to clear my workspace before the next cycle of the loop can start. I asked myself if it is possible to save and append files with the same file name created in the loop? I tried save with the option append but the new data replaces the old file with the same name.

Thanks in advance

StarkEffekt
From: Walter Roberson on
StarkEffekt Heiles wrote:

> For one of my research projects I have to deal with big matrices which
> are generated in a for loop. Since my memory is limited I have to clear
> my workspace before the next cycle of the loop can start. I asked myself
> if it is possible to save and append files with the same file name
> created in the loop? I tried save with the option append but the new
> data replaces the old file with the same name.

The only case that I _know_ of where save -append gives unexpected results is
if you are using binary files (the default) and the new variable you save has
the same name as an existing variable in the file. If you do have this
situation, then the entire .mat file will not be overwritten, but the new
contents of the variable will replace the old contents of the variable.
From: Steven Lord on

"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:hsuoof$7c0$2(a)canopus.cc.umanitoba.ca...
> StarkEffekt Heiles wrote:
>
>> For one of my research projects I have to deal with big matrices which
>> are generated in a for loop. Since my memory is limited I have to clear
>> my workspace before the next cycle of the loop can start. I asked myself
>> if it is possible to save and append files with the same file name
>> created in the loop? I tried save with the option append but the new data
>> replaces the old file with the same name.
>
> The only case that I _know_ of where save -append gives unexpected results
> is if you are using binary files (the default) and the new variable you
> save has the same name as an existing variable in the file. If you do have
> this situation, then the entire .mat file will not be overwritten, but the
> new contents of the variable will replace the old contents of the
> variable.

Walter, the behavior you describe as "unexpected" is actually the documented
behavior. Take a look in the description of "-append" in the Input
Arguments section of the documentation for SAVE:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/save.html?BB=1

In this case, '-append' means "add new variables to the file" not "add new
content to the variables already in the file". If either of you (or anyone
else) are interested in the latter meaning, I think that would make a
perfectly reasonable enhancement request to file with Technical Support
(along with your use case for how you'd use such a feature.) It would
likely be tricky to determine what it should do when used with the -ascii
flag, so if that scenario is important to you I suggest describing your
expectations in your request.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com