1 访问和更新回调中的 UI 组件内的数据
app.Component.Property
2 获取并设置一个仪表的 Value 属性
x = app.PressureGauge.Value; % Get the gauge value
app.PressureGauge.Value = 50; % Set the gauge value to 50
3 共享某个中间结果或多个回调需要访问的数据
应定义公共或私有属性来存储数据
公共属性在 App 内部和外部均可访问,而私有属性只能在 App 内部访问。
描述该属性
properties (Access = public)
X % Average cost
end
代码需要在 App 启动时访问某个属性值
在 properties 块或在 StartupFcn 回调中对其值进行初始化
% 初始化
properties (Access = public)
X = 5; % Average cost
end
% 在代码的其他位置,使用圆点表示法获取或设置属性的值
y = app.X % Get the value of X
app.X = 5; % Set the value of X
public,protected,private权限
Access=private:表示只有该类的成员方法可以访问该数据,而子类和其他外部函数无法访问该成员变量。
Access=protected:表示只有该类的成员方法还有该类的子类而已访问该数据。
public:在