Plotting negative x values in App Designer

조회 수: 9 (최근 30일)
Victoria L
Victoria L 2022년 7월 15일
댓글: Voss 2022년 7월 16일
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];

채택된 답변

Voss
Voss 2022년 7월 15일
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
Victoria L
Victoria L 2022년 7월 16일
Thank you very much for the clear clarification on vectors-- it is running perfect now with the two vectors included in plot!
Voss
Voss 2022년 7월 16일
Excellent - You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by