How to save fields of a struct through for loop iteration.

조회 수: 1 (최근 30일)
Habtamu Tesfaw
Habtamu Tesfaw 2020년 5월 16일
댓글: Habtamu Tesfaw 2020년 5월 18일
I have a struct with several field names.
data=
struct with fields:
'a': [100×1 double]
'b': [400×1 double]
.
.
etc.
I can save all the filed values to the same file as follow.
save(filename, 'a', 'b', ...)
but, since the field name are too many, I want to to save all of them by for loop. Is there any way I can do that? Thank you!

채택된 답변

Stephen23
Stephen23 2020년 5월 16일
편집: Stephen23 2020년 5월 16일
You don't need a loop, just use the -struct flag to save the fields of a scalar structure:
save(filename,'-struct','data')
When you load the file, make sure that you use an output argument:
data = load(filename);

추가 답변 (0개)

카테고리

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