필터 지우기
필터 지우기

saving a structure in mat file

조회 수: 1,009 (최근 30일)
genesis
genesis 2013년 7월 17일
댓글: Matthew Creek 2023년 8월 23일
i have a few structures i want to save in mat file. eg
s(1).a = 'hello'; s(1).b = 99; s(2).a = 'bye'; s(3).b = 82;
i want to save structure s(1) and s(2) into a mat file. i did this, save('test_struct.mat',marker(1)); but it give me error, Argument must contain a string.
  댓글 수: 3
genesis
genesis 2013년 7월 17일
sorry it was save('test_struct.mat',s(1));
Jan
Jan 2013년 7월 17일
@genesis: And now you have seen David's answer, which explains, that you need the string 's' instead of the variable s(1). If this solves your problem, please accept his answer.

댓글을 달려면 로그인하십시오.

채택된 답변

David Sanchez
David Sanchez 2013년 7월 17일
When using save, the name of the variable to be saved has to be a string:
s.name='ww';
s.age=22;
save('test.mat','s')
For structs, try the following, copied from matlab documentation:
Save the fields of structure s1 as individual variables. Check the contents of the file with the whos function. Clear the workspace and load the contents of a single field.
s1.a = 12.7;
s1.b = {'abc', [4 5; 6 7]};
s1.c = 'Hello!';
save('newstruct.mat', '-struct', 's1');
disp('Contents of newstruct.mat:')
whos('-file', 'newstruct.mat')
clear('s1')
load('newstruct.mat', 'b')

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by