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 Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by