Use two sliders to change a plot - not using GUIDE

1 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by