MATLAB系统对象的定义、使用与优化
1. 定义系统对象信息
在MATLAB中,我们可以为系统对象定义特定的显示信息。通过自定义 info 方法,能够为系统对象展示特定的信息。默认的 infoImpl 方法返回一个空结构体。而我们自定义的 infoImpl 方法,在使用 info(x,'details') 调用时返回详细信息,使用 info(x) 调用时仅返回计数信息。
以下是具体的代码实现:
methods (Access = protected)
function s = infoImpl(obj,varargin)
if nargin>1 && strcmp('details',varargin(1))
s = struct('Name','Counter',
'Properties', struct('CurrentCount',obj.Count, ...
'Threshold',obj.Threshold));
else
s = struct('Count',obj.Count);
end
end
end
完整的类定义文件如下:
classdef Counter < matlab
超级会员免费看
订阅专栏 解锁全文
1013

被折叠的 条评论
为什么被折叠?



