Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Habtamu Tesfaw
Habtamu Tesfaw le 16 Mai 2020
Commenté : Habtamu Tesfaw le 18 Mai 2020
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!

Réponse acceptée

Stephen23
Stephen23 le 16 Mai 2020
Modifié(e) : Stephen23 le 16 Mai 2020
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);

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by