How to get x-values in bar?

4 次查看(过去 30 天)
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)?

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-10-4
编辑:Dyuman Joshi 2023-10-4
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by