Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now