How to save -struct
76 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey, I'm having trouble saving this struct.
I've tried
save('datafile.mat','mati','-struct','materials');
when my code is something like:
mati = 1;
materials(mati).name = input('','s');
disp(strcat('Introduce the properties of the material',32,materials(mati).name,32,'in SI units.'));
disp('Density [Kg/m3]');
materials(mati).properties(1) = input('');
disp('fusion temp [K]');
materials(mati).properties(2) = input('');
disp('stress blab la [MPa]');
materials(mati).properties(3) = input('');
disp('Tensão de ruptura [MPa]');
But I get this error:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
0 Kommentare
Antworten (2)
Matt Fig
am 22 Nov. 2012
Bearbeitet: Matt Fig
am 22 Nov. 2012
According to the help for SAVE, you need to call like this:
save(filename, '-struct', structName, fieldNames)
Note that -struct is the second argument, not the third... But I wonder if all you need is this:
save('datafile.mat','materials');
For example:
clear all % Start with a clean slate
S.name = 'Iron'; % Build a structure
S.density = 2700;
S.CS = 'Fe';
save('myIron.mat','S') % Save the structure
clear all % Clear to make sure struct is gone.
load('myIron.mat') % Load it. (Also, X=load(...) is preferred)
whos % See if we have our structure back...
Name Size Bytes Class Attributes
S 1x1 548 struct
0 Kommentare
Oleg Isaev
am 11 Apr. 2018
https://www.mathworks.com/help/matlab/ref/matlab.io.savevariablestoscript.html
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!