Matlab的App Designer可以帮助我们快速编写简易的用户界面程序。本文是一个笔记,记录利用App Designer开发交互界面的一些tips。
1. 主体流程
1.1 一个最简单的DemoApp
在matlab主界面里面新建App(保存为DemoApp.mlapp),就可以进入App Designer。App Designer给我们提供了设计视图和代码视图。设计视图方便我们拖放各种控件,像按钮、文本框、坐标轴啊之类。代码视图是用来编写具体函数,按钮响应,交互逻辑之类。设计视图不用过多介绍,下面我们再看看代码视图里面的东西。
在matlab中,一个app就是一个类。我们打开代码视图,可以看到该类继承了matlab.apps.AppBase,它的主体结构如下
classdef DemoApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
....
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
....
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = DemoApp
...
end
% Code that executes before app deletion
function delete(app)
...
end
end
end