Fill in the callback function so that it gets the value of the slider, prints that value in the text box, and uses it to set the LineWidth of the plot (so, e.g., if the slider value is its maximum, the line width of the plot would be 5)
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:15.13
All Answers
total answers (1)
sliderlinewidth.m
function sliderlinewidth
f = figure('Visible', 'off','Position',[20,20,500,400]);
slhan = uicontrol('Style','slider','Units','Normalized',...
'Position',[.3 .3 .4 .1], ...
'Min', 1, 'Max', 5,'Value',3,'Callback', @callbackfn);
slval = uicontrol('Style','text',...
'Units','Normalized','Position', [.4 .1 .2 .1]);
axhan = axes('Units', 'Normalized','Position', [.3 .5 .4 .3]);
x = -2*pi:0.1:2*pi;
y = cos(x);
phan = plot(x,y)
set(f,'Visible','on');
function callbackfn(source,eventdata)
num=get(slhan, 'Value');
set(slval, 'String',num2str(num))
set(phan,'LineWidth',num)
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer