在MATLAB中保存用户定义的类

San*_*eep 2 arrays matlab class multidimensional-array

我在matlab中使用classdef作为,

classdef scores
    %   SCORES Summary of this class goes here
    %   Class for stroring the individual scores array of each of the
    %   comparison of the models and the test files including the number of
    %   coefficients used and number of gaussian 

    properties
        detailed_scores;
        no_of_gauss=0;
    end

    methods
    end
end
Run Code Online (Sandbox Code Playgroud)

创建对象并保存到数组中;

for i=1:99
    score = scores;
    score.detailed_scores = somescore(:,9);
    score.no_of_gauss = i;
    array = [array score];
end
Run Code Online (Sandbox Code Playgroud)

现在,我想将它保存到matfile中;

save('somematfile.mat','array');
Run Code Online (Sandbox Code Playgroud)

是否可以array稍后加载以检索数据?

Kav*_*vka 6

是的,load somematfile就是这样做的.

load somemathfile
for k = 1:length(array)
  obj = array(k);
  obj.detailed_scores
end
Run Code Online (Sandbox Code Playgroud)

但是,如果更改类定义,则必须小心,尤其是在删除/重命名或向类添加新属性时.在这种情况下,您可能需要实现saveobjloadobj方法.