Use two sliders to change a plot - not using GUIDE

1 回表示 (過去 30 日間)
Giorgio
Giorgio 2013 年 10 月 3 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by