MATLAB 面向对象编程示例
简单介绍MATLAB 面向对象编程的格式和思路.
classdef:MATLAB 类函数关键字
properties:类属性名称
methods :类方法名称
类函数:
classdef human % classdef properties methods---THREE KEYWORDS
properties
age
sex
high
end
methods
function obj = human(age,sex,high)
obj.age = age;
obj.sex = sex;
obj.high = high;
end
end
end
主程序
%% The following code works fine in MATLAB2019a
% author:alan Wang
% Date:20210112
% For Learn
%%
len = 10;
parfor i = 1 : len % In this row can replace 'parfor' with 'for'
man(i) = human(18 + i,'man',175 + i);
man(i).age
end
clear i
文件链接:https://pan.baidu.com/s/1Q6XvhzynpMKHDMmlxEOLXA
提取码:8hqz