Unable to set the scale fro -inf to inf

1 Ansicht (letzte 30 Tage)
Raghav Rathi
Raghav Rathi am 13 Jan. 2023
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

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 13 Jan. 2023
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 Kommentare
Raghav Rathi
Raghav Rathi am 13 Jan. 2023
That was really helpful thanks a lot. But why is the value corresponding to 'inf' which is '1' not being plotted?
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 13 Jan. 2023
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'})

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by