classdef (Attributes) ClassName < SuperclassName
properties (Attributes)
PropertyName
PropertyName size class {validation functions}
end
methods (Attributes)
function obj = methodName(obj,arg2,...)
...
end
end
events (Attributes)
EventName
end
end
classdef (Attributes) ClassName < SuperclassName
enumeration
EnumName
end
end
properties、methods、events 和 enumeration 也是 MATLAB® 函数的名称,这些函数用于查询给定对象或类名称的各个类成员。
从 handle
派生类
MySubclass
类派生自 handle
类。属性 set 方法不返回传递给该方法的对象,而值类有此要求:
classdef MySubclass < handle properties Client tcpclient end methods function set.Client(obj,c) if isa(c,'tcpclient') obj.Client = c; end end end end
创建 MySubclass
的对象,并将 tcpclient
对象分配给 Client
属性。
t = MySubclass; t.Client = tcpclient('www.mathworks.com', 80);