How can I save just the values of a structure in a .mat file?

1 vue (au cours des 30 derniers jours)
Christopher Guzman
Christopher Guzman le 17 Oct 2019
I have 2 structures with 5 fields. I would like to save the values in a .mat file, and later on append the next values of the second structure into that file.
The structures are also a combination of strings and doubles.

Réponses (1)

Walter Roberson
Walter Roberson le 17 Oct 2019
I would like to be sure that I understand what you are asking.
You have two structures that happen to have 5 fields each. You would like to store both structures into a single .mat file, ending up with two variables stored in the .mat file, one for each structure. Later, you would like to extend the second of those two structure variables in the .mat file. Are you extending by adding more fields, or are you extending by adding more elements -- for example extending a struct array of size 1 x 3 to a struct array of size 1 x 6 (each entry of which would have 5 fields) ?
If this is correct, then to extend a structure array inside a .mat file, there are two options:
  1. Load the variable from the .file, attempt to it, and save it back to the file. You can use the -append option of save to avoid overwriting the other variables. Note that the -append option overwrites all of an existing variable with the same name; you cannot, for example -append 3 more array elements to an existing variables and expect that it will go from 1 x 3 to 1 x 6.
  2. Use a -v7.3 .mat file, and use matFIle() . Changes to the variable are automatically saved into the file. matFile can read -v7 .mat files but it must be a -v7.3 mat file in order to write to it.

Catégories

En savoir plus sur Workspace Variables and MAT-Files 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