Plotting 2 arrays as bar charts with adjacent bars

조회 수: 7 (최근 30일)
Murtaza Mohammadi
Murtaza Mohammadi 2022년 11월 15일
댓글: Murtaza Mohammadi 2022년 11월 18일
I have two arrays A and B, each of 8 elements. I want to plot them as bar charts with each corresponding element plotted as adjacent bars. The bar tool overlaps and makes it difficult to handle the properties. The target is something like this (see image).
Thank you

채택된 답변

VBBV
VBBV 2022년 11월 15일
A = rand(1,8);
B = rand(1,8);
bar([1 2 3 4 5 6 7 8],[A;B]); % use concatenation

추가 답변 (1개)

Murtaza Mohammadi
Murtaza Mohammadi 2022년 11월 15일
I managed to achieve it by using the following command.
bar([1 2 3 4 5 6 7 8],vertcat(A, B));
Is there any solution more elegant?
Thanks

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by