필터 지우기
필터 지우기

How to save -struct

조회 수: 76 (최근 30일)
Rafael Monteiro
Rafael Monteiro 2012년 11월 22일
답변: Oleg Isaev 2018년 4월 11일
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.

답변 (2개)

Matt Fig
Matt Fig 2012년 11월 22일
편집: Matt Fig 2012년 11월 22일
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

Oleg Isaev
Oleg Isaev 2018년 4월 11일
https://www.mathworks.com/help/matlab/ref/matlab.io.savevariablestoscript.html

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by