How to get x-values in bar?

3 Ansichten (letzte 30 Tage)
Rounak Saha Niloy
Rounak Saha Niloy am 4 Okt. 2023
Bearbeitet: Dyuman Joshi am 4 Okt. 2023
I have some data which needs to be plotted in a bar plot.
My code is as follows:
x=[1:3,8];
y=[500 500 500 500
69 535 1354 42
97 498 1357 48
73 539 1328 60];
bar(x,y);
The output is as follows:
how to plot the graph so that there is no such space between 3 and 8 (as per the x-axis)?

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 4 Okt. 2023
Bearbeitet: Dyuman Joshi am 4 Okt. 2023
Change the x values to categorical data type -
x=[1:3,8];
y=[500 500 500 500
69 535 1354 42
97 498 1357 48
73 539 1328 60];
x=categorical(x);
bar(x,y);
Another workaround is to plot serially and then change the tick-labels
x=[1:3,8];
y=[500 500 500 500
69 535 1354 42
97 498 1357 48
73 539 1328 60];
bar(1:numel(x),y);
xticklabels(x)

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D 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