Appending structs in files

1 view (last 30 days)
Heidi
Heidi on 27 Jul 2015
Commented: Heidi on 27 Jul 2015
Depending on the length inputted, with this function I wish to append a new column to one of two structs, nmos and pmos, in an existing file. In this case, I wish to append new values in the nmos struct. The nmos struct contains many variables, such as beff, which in this example is: beff: [100x2 double].
pmos ------> beff, vgs, etc
nmos ------> beff, vgs, etc
This is the code I was using to try an append it to the file:
.
.
.
% if want to append data to existing file
else strcmp(filetype,'append')
save ('filename.mat','nmos','-append');
end
The problem is that each time I use a new length and try to append the new column it erases all the values from the previous columns. For example, nmos.beff becomes:
0 0.0019
0 0.0018
0 0.0018
0 0.0018
0 0.0017
0 0.0017
0 0.0016
0 0.0016
0 0.0016
0 0.0015
when trying to append a second column.
Is there a way to add these new columns without erasing all the previous values?

Answers (1)

Walter Roberson
Walter Roberson on 27 Jul 2015
The save -append flag is for adding complete new (named) variables without rewriting the entire file. It is not able to add additional information to an existing variable.
To add information to an existing variable you need to use matlabFile(). Or you need to read the existing value, add to it, and save the variable again.
  1 Comment
Heidi
Heidi on 27 Jul 2015
Okay I'll try loading and replacing them. Thank you!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!