Write a GUI function that will create a rectangle object. The GUI has a slider on top that ranges from 2 to 10
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:23.13
All Answers
total answers (1)
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