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!