2014-10-09 44 views
0

當我需要允許用戶指定要導入的集時,如何從.mat文件加載特定的一組數據?使用另一個變量名從.MAT文件加載特定列

例如:

a = 'setII'; % User specifies 
db = matfile('example.mat'); 
model = db.a; 

,這將閱讀作爲a'setII'然後基本上加載db.setII

當前它嘗試查找標記爲'a'的數據集時出錯。

回答

2

使用動態字段引用:

model = db.(a) 

如果a是包含在db字段/屬性的名稱,一個字符串,它的工作原理。

實施例具有的結構:

example = struct('name','test','values',[1 2 3 4], 'size', 4); 
fieldname = 'values'; 
x = example.(fieldname) 

返回

x = [1 2 3 4] 
相關問題