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

4 Ansichten (letzte 30 Tage)
cgenes
cgenes am 25 Nov. 2016
Bearbeitet: Adam am 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 Kommentare
cgenes
cgenes am 28 Nov. 2016
Bearbeitet: cgenes am 28 Nov. 2016
For anyone interested I solved my problem by deleting all the empty rows in the struct array, then joining the array from the previous.mat file with the newly created array
myArray = [previousArray, myArray]
then
save('myArray.mat', 'myArray')
Adam
Adam am 28 Nov. 2016
Bearbeitet: Adam am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by