필터 지우기
필터 지우기

How to save structure inside a structure in .mat file?

조회 수: 7 (최근 30일)
Grishma Gupta
Grishma Gupta 2019년 11월 8일
편집: karipuff 2023년 4월 26일
I want to save a structure S which contains 3 fields A,B,C which looks like :
A = [ 1,2,3,4, ... ]
B = [ 1,2,3,4, ... ]
C = 4*4 matrix.
I tried S.a = A, S.b = B , S.c = C
save('data','S');
but it stores it like
a:[1×107 double]
b: [1×39 double]
c: [39×107 double]
it dosent store the values.
Can anyone suggest how can i save the structure with values?

답변 (2개)

Guillaume
Guillaume 2019년 11월 8일
If S is indeed a structure as you have defined, then
save('data', 'S');
does indeed save the whole structure as one structure variable in the mat file. So you'll have to explain why you think it's not the case.
On the other hand, if you did:
save('data', '-struct', 's');
then this would save the field of the structure as individual variables, a, b, and c.

karipuff
karipuff 2023년 4월 26일
편집: karipuff 2023년 4월 26일
%%% Saving content of structure
a =
field1: {6x6 cell}
field2: {6x6 cell}
field3: {6x6 cell}
field4: {6x6 cell}
field_str = fieldnames(a);
save('filename.mat', field_str{:})
%%% Loading content of structure
b = load('filename.mat');
b =
field1: {6x6 cell}
field2: {6x6 cell}
field3: {6x6 cell}
field4: {6x6 cell}

카테고리

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