how to fix Y limits of the plot

4 visualizaciones (últimos 30 días)
Marat Zhe
Marat Zhe el 12 de Feb. de 2019
Editada: Marat Zhe el 14 de Feb. de 2019
__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 comentarios
Steven Lord
Steven Lord el 12 de Feb. de 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.
Marat Zhe
Marat Zhe el 12 de Feb. de 2019
Editada: Marat Zhe el 13 de Feb. de 2019
Hello Steven Lord. I want slider to be a part of the figure. As you can see, my script places slider on the figure. Thank's for interesting information about interactive control, but, as for as i understand, this function is available for 2018b user's. I have 2017a version. I added information about Matlab version to my question.

Iniciar sesión para comentar.

Respuesta aceptada

Marat Zhe
Marat Zhe el 14 de Feb. de 2019
Editada: Marat Zhe el 14 de Feb. de 2019
__Hi dear Matlab user's and staff. I think i've resolved my issue.
All i needed is to add code section
Axes_handle=axes;
set(Axes_handle,'NextPlot','replacechildren');
before "Plot_sinus" function call in main function body.
__Thanks for your attention.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by