Appending structs in files

조회 수: 1 (최근 30일)
Heidi
Heidi 2015년 7월 27일
댓글: Heidi 2015년 7월 27일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 7월 27일
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
Heidi
Heidi 2015년 7월 27일
Okay I'll try loading and replacing them. Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by