필터 지우기
필터 지우기

assign loaded structs directly

조회 수: 3 (최근 30일)
geieraffe
geieraffe 2014년 10월 29일
답변: Titus Edelhofer 2014년 10월 29일
I wonder, if there is no nicer way for doing this:
mdlPara = load([datasetPath,datasetName]);
rename = fieldnames(mdlPara);
mdlPara = mdlPara.(rename{1});
I want to load different named structs in my script. For acessing the data in the script I want them to have the same name (mdlPara). But with just loading them the struct is named
mdlPara.OLDSTRUCTNAME.Data. ...
is there a nicer way to get the form
mdlPara.Data. ...
directly

답변 (2개)

Matt J
Matt J 2014년 10월 29일
편집: Matt J 2014년 10월 29일
No, I don't think there is a shorter way, but to avoid typing this repeatedly, you can just wrap it in a function,
function mldPara = loadfirstvar(varargin)
mdlPara = load(varargin{:});
rename = fieldnames(mdlPara);
mdlPara = mdlPara.(rename{1});

Titus Edelhofer
Titus Edelhofer 2014년 10월 29일
Hi,
not really. But what you can do is to save the data as individual variables originally. So when you save your structure OLDSTRUCTNAME, do
save('thefile.mat', '-struct', 'OLDSTRUCTNAME');
When you load them afterwards, you don't have the structure name in mdlPara.
Titus

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by