MATLAB Answers

0

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

Asked by Grishma Gupta on 8 Nov 2019 at 16:31
Latest activity Answered by Guillaume
on 8 Nov 2019 at 17:03
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?

  0 Comments

Sign in to comment.

1 Answer

Answer by Guillaume
on 8 Nov 2019 at 17:03

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.

  0 Comments

Sign in to comment.