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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!