Use two sliders to change a plot - not using GUIDE
1 view (last 30 days)
Show older comments
I would like to change my grap of sin(x*a)+m controlling a and b by using two sliders. This is my code, how could I modify commented code to make it work?
function plot()
close all
%# setup GUI
hFig = figure('menu','none');
hAx = axes('Parent',hFig);
%first slider
uicontrol('Parent',hFig, 'Style','slider', 'Value',1, 'Min',-1,...
'Max',4, 'SliderStep',[0.05 0.1], ...
'Position',[150 5 300 20], 'Callback',@slider1_callback)
hTxt1 = uicontrol('Style','text', 'Position',[460 8 20 15], 'String','0');
% %second slider
% uicontrol('Parent',hFig, 'Style','slider', 'Value',1, 'Min',-1,...
% 'Max',4, 'SliderStep',[0.05 0.1], ...
% 'Position',[150 35 300 20], 'Callback',@slider2_callback)
% hTxt2 = uicontrol('Style','text', 'Position',[460 38 20 15], 'String','0');
%# Callback function
function slider1_callback(hObj, eventdata)
a = get(hObj,'Value');
m = 1; %***I wish it depends by the second slider***
x = -3:0.001:3;
y=sin(x*a) + m;
plot(hAx,x,y,'.r')
set(hTxt1, 'String',num2str(a)) %# update text
% set(hTxt2, 'String',num2str(b)) %# update text
% # Callback function
% function slider2_callback(hObj, eventdata)
% a = 1; %***I wish it depends by the first slider***
% m = get(hObj,'Value');
% x = -3:0.001:3;
% y=sin(x*a) + m;
% plot(hAx,x,y,'.r')
% set(hTxt1, 'String',num2str(a)) %# update text
% set(hTxt2, 'String',num2str(b)) %# update text
% end
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!