Unable to set the scale fro -inf to inf

1 次查看(过去 30 天)
Hi,
I am trying to plot 2 arrays but I am not getting the expected result. I am sure I am making some mistake but I am unable to identify it.
x = [1 0.93 1 0.96 1 1 1 0.86];
snr = [Inf 9 -0.539 -4.98 -7.9 -10.08 -11.83 -13.28];
plot(snr,x)
ylim([0 1])
xlim([-inf inf])
Firstly, the plot is missing the value at 'inf' which is 1 and second, I am trying to make the scale of x axis from -inf to inf but that is not working.
I am actually trying to make the x axis ticks as [ -inf -15 -10 -5 0 5 10 15 int] but i am still trying to figure out how to do that.
Can someone help me with this. Any help is appreciated.
Thank you

回答(1 个)

Sulaymon Eshkabilov
Note that [inf -inf] will make your plot hardly visible and thus, you had better take a bit larger values to the two extreme points, e.g.:
x = [1 0.93 1 0.96 1 1 1 0.86];
snr = [Inf 9 -0.539 -4.98 -7.9 -10.08 -11.83 -13.28];
plot(snr,x, 'ro-', 'linewidth', 2), grid on
ylim([0 1])
xlim([-25 25])
xticks([-25 -15 -10 -5 0 5 10 15 25])
xticklabels({'-inf', '-15', '-10', '-5', '0', '5', '10', '15', 'inf'})
  2 个评论
Raghav Rathi
Raghav Rathi 2023-1-13
That was really helpful thanks a lot. But why is the value corresponding to 'inf' which is '1' not being plotted?
Sulaymon Eshkabilov
Here is how you can make it visible:
x = [1 0.93 1 0.96 1 1 1 0.86];
snr = [-25 9 -0.539 -4.98 -7.9 -10.08 -11.83 -13.28];
[SNR, IND] = sort(snr);
X = x(IND);
plot(SNR,X, 'ro-', 'linewidth', 2), grid on
ylim([0 1])
xlim([-25 25])
xticks([-25 -15 -10 -5 0 5 10 15 25])
xticklabels({'-inf', '-15', '-10', '-5', '0', '5', '10', '15', 'inf'})

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by