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!