Saving to .mat without additional struct.
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gabriel ROUX
el 8 de Jul. de 2022
Comentada: Steven Lord
el 8 de Jul. de 2022
I have that structure
test =
struct with fields:
F0: 243000
I: [3×3 double]
I_1: [3×3 double]
I_X: 5550000
I_XZ: 33000
%[...]
m: 160000
that i want to save 'as it is'
uisave('test')
I save it as name ('test2'), i load it back and i go this
aircraftdata = load('test2.mat')
aircraftdata =
struct with fields:
test: [1×1 struct]
What i want is a structure like this :
aircraftdata =
struct with fields:
F0: 243000
I: [3×3 double]
I_1: [3×3 double]
I_X: 5550000
I_XZ: 33000
%[...]
m: 160000
The whole point is saving the structure untouched and load it with a new name
0 comentarios
Respuesta aceptada
Steven Lord
el 8 de Jul. de 2022
When you save the struct array, specify the '-struct' option. This will save each of the struct fields separately in the MAT-file. When you call load with an output argument, each of those separate pieces of data from the MAT-file will become fields of the new struct.
S = struct('theAnswer', 42, 'magicMatrix', magic(5), 'nephews', ["Huey", "Dewey", "Louie"])
cd(tempdir)
name = 'temporaryMatfile.mat';
save(name, '-struct', 'S')
whos('-file', name) % Individual variables
data = load(name)
Compare with:
name2 = 'otherTemporaryMatfile.mat';
save(name2, 'S')
whos('-file', name2) % The struct was stored intact
data = load(name2)
data.S
2 comentarios
Steven Lord
el 8 de Jul. de 2022
I don't believe uisave offers the '-struct' option. You could try using a different tool, like uiputfile, to select the file to which you want to save. Once you have the file name and path information, use fullfile to construct the fully qualified name and pass name that into save.
Más respuestas (2)
Steve Eddins
el 8 de Jul. de 2022
Try this:
s = load("test2.mat");
aircraftdata = s.test;
0 comentarios
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!