Saving structure as a .mat file with matrices, strings and numbers

20 vues (au cours des 30 derniers jours)
Joaquin Batista
Joaquin Batista le 18 Sep 2019
Commenté : Joaquin Batista le 23 Sep 2019
I have a very large structure full of data that fails to save as a .mat file. Some feilds have strings while other have scalars while others have matrices.
save('data.mat', '-struct', s)
Save does not workk in this case, I suspect because its not a scalar but in the save help page we can save structures.
The error I get is:
"Error using save"
"Must be a string scalar or character vector."
and if I add the '-struct' delimiter I get the error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.

Réponse acceptée

Rik
Rik le 18 Sep 2019
There are two issues here. If you read the doc it specifies that the struct must be scalar (each field is allowed to be any type or size). It also still requires you to enter the variable name as a char.
save('data.mat', '-struct', 's')%will only work if s is a scalar struct
If your struct is an array, you will either have to make it a scalar struct, or avoid the struct syntax.
%example:
s_wrapped=struct('content',s);
save('data.mat', '-struct', 's_wrapped')
  3 commentaires
Rik
Rik le 19 Sep 2019
Thank you for pointing this out.
I was just describing how you could use the '-struct' syntax without having a scalar struct. I don't know what the benefit would be, but this does work. I suspect the first syntax is actually the one that Joaquin is looking for, making a discussion about the usefulnes of the second moot.
Joaquin Batista
Joaquin Batista le 23 Sep 2019
Yes, it worked out thank y'all very much!! I used the second example and it saved properly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by