有结构的组织
您可以输入struct
具有这些参数的字段作为字段。
例如具有字段的结构
setts.TrainNeg
.TrainPos
.nf
.nT
.factors
.removeEachStage
.applyEstEachStage
.removeFeatures
这样,当您设置字段时,就可以清楚地知道该字段是什么,这与您必须记住参数顺序的函数调用不同。
然后你的函数调用变成
[Model threshold] = detect(setts);
你的函数定义就像
function [model, threshold] = detect(setts)
然后只需将出现的 eg 替换param
为setts.param
。
混合方法
如果您愿意,也可以将这种方法与您当前的方法混合使用,例如
[Model threshold] = detect(in1, in2, setts);
如果您仍想明确包含in1
and in2
,并将其余部分捆绑到setts
.
面向对象的方法
另一种选择是将检测变成一个类。这样做的好处是detect
对象将具有具有固定名称的成员变量,而不是结构,如果在设置字段时打错字,您只需创建一个名称拼写错误的新字段。
例如
classdef detect()
properties
TrainNeg = [];
TrainPos = [];
nf = [];
nT = [];
factors = [];
removeEachStage = [];
applyEstEachStage = [];
removeFeatures =[];
end
methods
function run(self)
% Put the old detect code in here, use e.g. self.TrainNeg to access member variables (aka properties)
end
end