【问题标题】:Saving User Defined Class in MATLAB在 MATLAB 中保存用户定义的类
【发布时间】:2011-12-13 01:08:32
【问题描述】:

我在 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

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

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

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

save('somematfile.mat','array');

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

【问题讨论】:

    标签: arrays class matlab multidimensional-array


    【解决方案1】:

    是的,load somematfile 会这样做。

    load somemathfile
    for k = 1:length(array)
      obj = array(k);
      obj.detailed_scores
    end
    

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

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 2010-12-01
      • 2020-03-10
      • 2014-05-07
      • 2021-04-25
      • 2015-12-04
      • 2013-04-14
      • 2015-12-19
      • 1970-01-01
      相关资源
      最近更新 更多