Q:

Write a GUI function that will create a rectangle object. The GUI has a slider on top that ranges from 2 to 10

0

 The value of the slider determines the width of the rectangle. You will need to create axes for the rectangle. In the callback function, use cla to clear the children from the current axes so that a thinner rectangle can be viewed. 

All Answers

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

guirectangle.m

function guirectangle

f = figure('Visible', 'off','Position', [360, 500, 400,400]);

minval = 2;

maxval = 10;

slhan = uicontrol('Style','slider','Position',

[140,280,100,50], ...

 'Min', minval, 'Max', maxval,'Value',minval,'Callback', 

@callbackfn);

hmintext = uicontrol('Style','text','BackgroundColor', 

'white', ...

 'Position', [90, 310, 40,15], 'String', num2str(minval));

hmaxtext = uicontrol('Style','text', 'BackgroundColor', 

'white',...

 'Position', [250, 310, 40,15], 'String', num2str(maxval));

hsttext = uicontrol('Style','text','BackgroundColor', 'white',...

 'Position', [170,340,40,15],'Visible','off');

axhan = axes('Units', 'Pixels','Position', [100,50,200,200]);

set(f,'Name','Rectangle GUI')

movegui(f,'center')

set([slhan,hmintext,hmaxtext,hsttext,axhan], 

'Units','normalized')

set(f,'Visible','on');

 function callbackfn(source,eventdata)

 num=get(slhan, 'Value');

 set(hsttext,'Visible','on','String',num2str(num))

 cla % deletes all children of current axes

 rh = rectangle('Position',[5,5,5,10]);

 axis([0 30 0 30])

 set(rh,'LineWidth',num)

 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