gpt4 book ai didi

arrays - 在 MATLAB 中保存用户定义的类

转载 作者:行者123 更新时间:2023-12-02 03:42:30 25 4
gpt4 key购买 nike

我在 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');

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

最佳答案

是的,load somematfile 就可以做到这一点。

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

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

关于arrays - 在 MATLAB 中保存用户定义的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8483159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com