[Matlab] User Interface Functions
Posted on Saturday, February 4, 2012, 10:15 AM
One easy method for creating a user interface is a question dialog. This can easily be used with the switch function to run different sections of code.
SelectFunction = questdlg('What do you want to do?', ...
'Select Function', ...
'Get data from images', 'Get Amplitude information from data','Plot displacement vs. time','Get data from images');
switch SelectFunction
%% Input data from images
case 'Get data from images'
'Select Function', ...
'Get data from images', 'Get Amplitude information from data','Plot displacement vs. time','Get data from images');
switch SelectFunction
%% Input data from images
case 'Get data from images'
'Stuff'
case 'Get Amplitude information from data'
'more stuff'
A more complex but useful process is this:
function UserInterfaceExample
% User Interface Example
% Creates a box with buttons which execute functions
clear;clc;close all;
height = 250;
width = 200;
figure
set(gcf,'Position',[1000 height+200 width height],'Menubar','none')
uicontrol('Style', 'pushbutton', 'String', 'Say Hi',...
'Position', [50 height-50 100 20],...
'Callback', @Function1);
uicontrol('Style', 'pushbutton', 'String', 'Say Bye',...
'Position', [50 height-100 100 20],...
'Callback', @Function2);
uicontrol('Style', 'pushbutton', 'String', 'Draw a Line',...
'Position', [50 height-150 100 20],...
'Callback', @Function3);
uicontrol('Style', 'pushbutton', 'String', 'Draw Shapes',...
'Position', [50 height-200 100 20],...
'Callback', @Function4);
end
function Function1(src,evt)
clear;clc;close all;
fprintf('HI')
end
function Function2(src,evt)
clear;clc;close all;
fprintf('Bye!')
end
function Function3(src,evt)
clear;clc;close all;
figure
line([2 5],[2 5])
end
function Function4(src,evt)
clear; clc; close all;
figure
rectangle('Position',[200 200 300 500],'Curvature', [0 0])
rectangle('Position',[10 10 300 500],'curvature',[1,1])
axis square
end
other functions:
uicontrol
uigetdir
uigetfile
inputdlg
inputdlg
errordlg
helpdlg
listdlg
msgbox
questdlg
uiresume
uiwait
warndlg
end
helpdlg
listdlg
msgbox
questdlg
uiresume
uiwait
warndlg
Subscribe to:
Post Comments (Atom)
No Response to "[Matlab] User Interface Functions"
Leave A Reply