Write a function that will create a GUI in which there is a plot. Use a button group to allow the user to choose among several functions to plot
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:22.13
All Answers
total answers (1)
guiChooseFnPlot.m
function guiChooseFnPlot
% Plots a function of x, allowing user to choose
% function with a button group
% Format of call: guiChooseFnPlot
% Does not return any values
f = figure('Visible','off','Position',...
[360, 500, 400, 400]);
% Create button group for function choice
grouph = uibuttongroup('Parent',f,'Units','Normalized',...
'Position', [.3 .7 .3 .2], 'Title','Choose Function',...
'SelectionChangeFcn', @whichfn);
sinh = uicontrol(grouph,'Style','radiobutton',...
'String', 'sin', 'Units','Normalized',...
'Position',[.2 .7 .4 .2]);
cosh = uicontrol(grouph,'Style','radiobutton',...
'String','cos','Units','Normalized',...
'Position',[.2 .4 .4 .2]);
set(grouph, 'SelectedObject', [])
% Axis handle for plot
axhan = axes('Units', 'Normalized', 'Position', [.2 .1 .5 .5]);
set(f,'Name','Choose Function Plot')
movegui(f, 'center')
set(f, 'Visible', 'on')
function whichfn(source, eventdata)
which = get(grouph, 'SelectedObject');
x = -3 : 0.1 : 3;
if which == sinh
y = sin(x);
plot(x,y)
else
y = cos(x);
plot(x,y)
end
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer