how to fix Y limits of the plot
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
__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 commentaires
Steven Lord
le 12 Fév 2019
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!