Write a function that will create a GUI in which there is a plot of cos(x). There should be two editable text boxes in which the user can enter the range for x
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:21.13
All Answers
total answers (1)
guiCosPlot.m
function guiCosPlot
% Plots cos(x), allowing user to enter range
% Format of call: guiCosPlot
% Does not return any values
f = figure('Visible','off','Position',...
[360, 500, 400, 400]);
% Edit boxes for min and max of x range
hmin = uicontrol('Style', 'edit','BackgroundColor',...
'white', 'Position', [90, 285, 40, 40]);
hmax = uicontrol('Style', 'edit', 'BackgroundColor', ...
'white', 'Position', [250, 285, 40, 40], ...
'Callback', @callbackfn);
% Axis handle for plot
axhan = axes('Units', 'Pixels', 'Position', [100,50,200,200]);
set(f,'Name','Cos Plot Example')
movegui(f, 'center')
set([hmin, hmax], 'Units','Normalized')
set(f, 'Visible', 'on')
% Callback function displays cos plot
function callbackfn(source, eventdata)
% Called by maximum edit box
xmin = get(hmin, 'String');
xmax = get(hmax, 'String');
x = linspace(str2num(xmin),str2num(xmax));
y = cos(x);
plot(x,y)
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer