how to fix Y limits of the plot
조회 수: 3 (최근 30일)
이전 댓글 표시
__Hi guys!! I have a Matlab script. Here i want to change amplitude of sin function on the figure, using slider.
(It's just an exhample. Original script is much bigger)
function f
close all
global x Ampl
x=0:0.1:360;
Ampl=1;
Sl_default=1;
Sl_min=0.5;
Sl_max=3;
SSlider = uicontrol('Style', 'slider',...
'Min',Sl_min,'Max',Sl_max,'Value',Sl_default,'SliderStep',[0.05,0.5],...
'Position', [0 40 120 20],...
'Callback', @Slider_ampl_function);
Plot_sinus;
xlim([0, 360]);
ylim([-1, 1]);
set(gca,'xtick',linspace(0,360,13),'ytick',linspace(-1,1,11));
set(gca,'Units','pixels','Position',[150,70,350,350]);
grid on;
end
function Slider_ampl_function(SSlider,eventdata)
global Ampl
Ampl = get(SSlider,'Value');
uicontrol('Style', 'text', 'String', ['amplitude= ',num2str(Ampl)],...
'Position', [130 40 120 20]);
Plot_sinus;%
end
function f=Plot_sinus
global x Ampl
y=Ampl*sind(x);
plot(x,y,'Color','k','LineWidth',2);
end
__The question is: is it possible to fix Ymin (=-1), Ymax(=1) and Ystep(=0.2) on Y axis, so that they doesn't depend on slider.
Of course, i can copy a part of the script
ylim([-1, 1]);
set(gca,'xtick',linspace(0,360,13),'ytick',linspace(-1,1,11));
inside function "Plot_sinus" after plot(...), so Matlab will set correct Ymin, Ymax and Ystep everytime i plot new curve.
But may be there is another, more elegant way to set them only one time. Matlab version 2017a.
댓글 수: 2
Steven Lord
2019년 2월 12일
Do you want the slider to be part of the figure or part of the script? If the latter, use the Live Editor and add an interactive control.
채택된 답변
추가 답변 (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!