save('-append') does not work ; what am i doing wrong?
Show older comments
Hi
I load in a .mat file into my script which contains a structure array of various variables - one of them the name of some images - the names of the images are pic1, pic2 etc. So the variable is PictureName and then there are rows pictures numbered 1:n
if pic1 and pic2 are already in the .mat file, but I run through my code and want to add pic3 and pic4 to the same .mat file that works fine
But if i start off with pic3 and pic4, and then try and add pic1 and pic2 in a next run through of the code - it overwrites pic3 and pic4 , and i'm just left pic1 and pic2!!
doing save('myfilename.mat', 'myStructuredArrayName') or save('my filename.mat', 'myStructuredArrayName', '-append') doesn't make any difference
what can i do?
thanks
4 Comments
Adam
on 25 Nov 2016
Well the second option is a different filename. Is that just a typo in your question or in your code too?
Jan
on 25 Nov 2016
We need to see the code, which reproduces the behavior.
Actually, I didn't pick up fully on all the details of the question before. What you see is the expected and documented behaviour of append. The append option adds new variables to an existing mat file in addition to those already there, but if a variable already exists it will overwrite that variable, it doesn't append within a single variable.
So the 'read it in, concatenate and write it out again' approach is what is needed here if you are sure you want everything saved within the same variable in your mat file.
Answers (0)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!