test_popup.m

来自「基本的matlab编程源代码」· M 代码 · 共 34 行

M
34
字号
function test_popup()
% This function creates a popup menu and a text field.
% The the associated callback will cause the option 
% selected in the popup menu to be displayed in the
% text field.

% First, create a cell array of options
options{1} = 'Option 1';
options{2} = 'Option 2';
options{3} = 'Option 3';
options{4} = 'Option 4';
options{5} = 'Option 5';

h0 = figure('Color',[0.8 0.8 0.8], ...
   'Name','Test Popup Menu', ...
   'NumberTitle','off', ...
   'Position',[300 300 257 136], ...
   'Tag','Fig1');
h1 = uicontrol('Parent',h0, ...
   'Units','points', ...
   'BackgroundColor',[0.8 0.8 0.8], ...
   'Position',[45 45 70 17], ...
   'String','Option 1', ...
   'Style','text', ...
   'Tag','Label1');
h1 = uicontrol('Parent',h0, ...
   'Units','points', ...
   'Callback','test_popup_callback', ...
   'Position',[45 25 70 17], ...
   'String',options, ...
   'Style','popupmenu', ...
   'Value',1, ...
   'Tag','Popup1');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?