필터 지우기
필터 지우기

save() and load() Variables in Object of correct Class

조회 수: 2 (최근 30일)
afalv
afalv 2017년 11월 27일
답변: afalv 2017년 11월 27일
map = containers.Map();
map('key') = 'value';
strg = 'string';
whos
save('workspace6.mat', 'map', 'strg', '-v7.3');
whos -file workspace6.mat
map2 = load('workspace6.mat', 'map');
strg2 = load('workspace6.mat', 'strg');
whos
gives:
Name Size Bytes Class Attributes
map 1x1 8 containers.Map
strg 1x6 12 char
Name Size Bytes Class Attributes
map - 8 containers.Map
strg 1x6 12 char
Name Size Bytes Class Attributes
map 1x1 8 containers.Map
map2 1x1 184 struct
strg 1x6 12 char
strg2 1x1 188 struct
It seems like it knows what type is in the file. But loaded back into a workspace variable it makes everything a struct. How do I get the data as an object of the correct class (including all sub-objects, if possible)?
I tried with and without '-v7.3' arguemnt.

채택된 답변

afalv
afalv 2017년 11월 27일
OK, got it:
ws = load('workspace6.mat');
map2 = ws.map;
strg2 = ws.strg;

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by