Plotting negative x values in App Designer
9 次查看(过去 30 天)
显示 更早的评论
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];

0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
