필터 지우기
필터 지우기

Save a structure that is within a structure

조회 수: 30 (최근 30일)
Matt
Matt 2018년 11월 7일
댓글: Matt 2018년 11월 7일
I am trying to save a structure called UserData that is in the handles structure - used in my GUI.
So far I can only save it if I create a copy outside of the handles structure.
UserData = handles.UserData
save(FullPath,UserData)
Is there a way to do it with simply the save function? Something like this:
save(FullPath, handles.'Car')
If there is I have not found the correct syntax to do so.

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 7일
You can save a structure from within a structure only in the very limited case that the parent structure is a scalar structure array and that all fields within the parent structure are to individually become variables in the mat file. The handles structure is a scalar structure so it meets the first requirement but it is quite unlikely that you want to save all parts of it to become individual variables.
It is likely that you will need to save the content of the substructure to a variable and then save the variable.
Car = handles.Car;
save(FullPath, 'Car')
The one exception I mentioned would look like
save(FullPath, '-struct', 'handles')
  댓글 수: 1
Matt
Matt 2018년 11월 7일
Apologies for my jumbled code. "Car" in code block 2 should have been "UserData" for continuity.
Thanks for your answer. I noticed that the parent structure isn't a scalar structure array, so I will have to go with the first solution - which I have already done incidentally.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by