MATLAB Answers

save('-append') does not work ; what am i doing wrong?

4 views (last 30 days)
cgenes
cgenes on 25 Nov 2016
Edited: Adam on 28 Nov 2016
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
Adam on 28 Nov 2016
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.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!