matlab 语法的简便,在 GUI 上也不遑多让呀;

  • uigetfile

    [filename, pathname] = uigetfile('*.m', 'choose a m file')

1. 创建对话框程序

button = questdlg('qstring','title','str1','str2',default) 
            % 第一个参数:显示的字符串
            % 第二个参数:表示对话框的标题
            % 后续可变参数表示,不同的按钮
            % 最后一个字符串为默认选定的按钮,(需在前面已经出现)
            % 返回值为选中的按钮对应的文本类型
button = questdlg('qstring','title','str1','str2','str1') 


matlab GUI 编程_其他

2. 交互式获取矩形区域的坐标

>> rect = getrect
                            % in current axes
>> rect = getrect(fig)
                            % in the current axes of
figure fig
>> rect = getrect(ax)
                            % in the axes specified by
the handle ax.

Use the mouse to click and drag the desired rectangle(用鼠标拖拽获得期望的矩形区域). rect is a four-element vector with the form [xmin ymin width height](返回值是四个元素构成的一个vector). To constrain the rectangle to be a square, use a shift- or right-click to begin the drag.(想要限制这个矩形为一个正方形,使用shift或者单击右键开始拖拽)

3. 输入框

prompt = {'Enter image name:', 'Enter colormap name:'};
title = 'Image display - assignin example';
lines = 1;
def = {'my_image', 'hsv'};

answer = inputdlg(prompt, title, lines, def);
            % answer 接收输入框文本的值;

assignin('base', 'imfile', answer{1});
assignin('base', 'cmap', answer{2});
            % 在 base workspace 下创建两个变量,imfile,cmap,并赋字符串值