Plotting negative x values in App Designer

9 visualizaciones (últimos 30 días)
Victoria L
Victoria L el 15 de Jul. de 2022
Comentada: Voss el 16 de Jul. de 2022
I am new to MatLab (and App Desiger), and am trying to plot a function that will respond to values adjusted with three different sliders. I have the sliders working now, but I am having a difficult time with my x-axis. Specifically, no negative values of x will be plotted even when I specify that x can be negative using linspace and also when specifying the XLim. All of my x values seem to be +1 of what they should be...
I've tried reading the forums and I believe it is because there is "no non-positive indexing" in MatLab.... but I am rather stuck now on how to proceed. Any appreciate is greatly appreciated!
function Plot2ButtonPushed(app, event)
x = linspace(-10,10);
V = app.V_1Slider.Value; % in eV
k = 8.6173*10^(-5); %eVK^-1
h = 4.1357*10^(-15); % in eVs
lla = app.Slider_3.Value;
T = app.TSlider.Value; %in K
%let ln(ket) = lket
a = log((2*pi/h)*V.^(2)*1/sqrt(4*pi*lla*k*T));
lket = a-(((lla + (-1)*x).^(2))/4*lla*k*T);
plot(app.UIAxes_2,lket,'b')
app.UIAxes_2.XLim = [-10 10];

Respuesta aceptada

Voss
Voss el 15 de Jul. de 2022
Try this:
plot(app.UIAxes_2,x,lket,'b')
Generally arguments to plot come in x/y pairs. That is, you specify the x values and then the corresponding y values for each line you want to plot. If you only specify a single vector, then that's treated as y, and it is plotted against the indices 1:numel(y).
So you are correct: the reason you don't get any negative x values is because you've given plot one vector to plot. Give it two vectors and you'll get a plot with negative x (if there are negative values in the x you give it, of course), as above.
  2 comentarios
Victoria L
Victoria L el 16 de Jul. de 2022
Thank you very much for the clear clarification on vectors-- it is running perfect now with the two vectors included in plot!
Voss
Voss el 16 de Jul. de 2022
Excellent - You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by