AppDesigner 笔记
1、对话框
模态对话框:关键字为 “modal” ,功能是若不关闭它,将无法访问图窗。但它不会阻止其他对话框出现。
% uiwait()
uiwait( msgbox("Hello world !","Welcome","modal") );% 感觉没有效果,需进一步研究。。。
% 也可使用uialert函数(好用)
uialert(fig,message,title)
% 在指定图窗窗口的前面显示一个模态对话框。图窗必须使用 uifigure 函数创建。此对话框中显示指定的消息,并在标题栏中显示指定的标题。默认情况下,此对话框还包含一个错误图标和一个确定按钮。
% example1:
fig = app.UIFigure;
message = sprintf('Hello world! \n 这是一个对话框.');
uialert(fig, message,'Warning','Icon','');% 图标见下附图
******************************************************************
注;
学习使用以下函数:
sprintf(); uiwait(); uialert();
其他对话框:
questdlg("问题?","标题","选项1","选项2","选项1");
errordlg(); warndlg();
******************************************************************
2、一些常用的函数和命令(详细用法参看帮助文档)补充ing!
************* 文件操作 ***************************
% 读文件接口
uigetfile(); uigetdir();
% 写文件接口
uiputfile(); uiputdir();
% 其他文件操作函数
拼接路径与文件名: fullfile();
保存:saveas(gcf,'**.png');
另存为:
*************************************************
************* 字符串操作 ***************************
% 字符串拼接 字符串比较
strcat(); strcmp();
% 变量格式化为
sprintf()
*************************************************
************* 界面命令 ***************************
% 返回 退出
return delete(app);
% 清空图窗---------------好重要的!!!!-----------
delete(allchild(app.UIAxes));
% 第二种方法:
cla(app.UIAxes2,"reset"); % 清除图窗
*************************************************
% 分割数据函数
regexp(data,'\r\n','split');
% 三维绘图
surf(ax,___);% 曲面图
mesh(ax,___);% 网格曲面图
3、一些函数的使用
% 1.对话框
fig = app.UIFigure;
message = sprintf('Hello world! \n 这是一个对话框。');
uialert(fig, message,'Warning','Icon','success');
% 2.进度条对话框(实时显示进度条应该怎么搞?)
fig = app.UIFigure;
d = uiprogressdlg(fig,'Title','Please Wait',...
'Message','Opening the application');
close(d);
% 3.确认关闭程序(选择对话框)
sel = questdlg("确认关闭程序?","关闭程序","Yes","No","No");
switch sel
case "Yes"
delete(app);
case "No"
return;
end
% 4.try——catch语句
try
% 执行语句块1
catch
% 执行语句块2
end
% 注: 1.对待内存泄露的问题可以尝试使用 try-catch 语句
% 2.catch语句不知道写什么时,就写 return
% 5.以下两个函数可用于两个函数中共享变量:
setappdata(app.Button_3,'data1',data);
data = getappdata(app.Button_3,'data1');
% 注: data一般可定义为结构体类型以便传输多种不同的参数、
4、关于绘图的一些函数
set() % 设值图形相关参数,字体、样式、线宽、颜色...