How do I stack an array variable and plot three of these stacked array variables on a barh?

% S
a1 = [2 2 3];
b1 = [2 5 6];
c1 = [0 8 9];
d1 = [2 0 12];
e1 = [2 0 12];
% H
a2 = [3 6 2];
b2 = [2 5 6];
c2 = [0 8 9];
d2 = [2 0 12];
e2 = [2 0 12];
% HS
a3 = [1 1 3];
b3 = [2 5 6];
c3 = [0 8 9];
d3 = [2 0 12];
e3 = [2 0 12];
a = [a1; a2; a3];
b = [b1; b2; b3];
c = [c1; c2; c3];
d = [d1; d2; d3];
e = [e1; e2; e3];
% T
t = [1 2 3 4 5];
dates = [a1 a2 a3; b1 b2 b3; c1 c2 c3; d1 d2 d3; e1 e2 e3];
% Plotted
figure
barh(t, d, 'hist')
If you plot this, you will notice that there are 9 bar graphs associated with each 't'. There should be only three as stated in the 'dates' variable per t. How do I stack 'a1,a2,a3, then b1,b2,b3 ...... and e1,e2,e3 each individually' to accomplish this feat?

답변 (1개)

In the above code, each of a1, a2, a3, b1,...e3 are itself vectors and not scalars. The value of the dates array is
dates =
2 2 3 3 6 2 1 1 3
2 5 6 2 5 6 2 5 6
0 8 9 0 8 9 0 8 9
2 0 12 2 0 12 2 0 12
2 0 12 2 0 12 2 0 12
As you can see there are 9 columns and hence there would be 9 bars for each value in t.
Refer to Input Arguments x & y of the function barh for more information.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

N/A
2020년 4월 4일

댓글:

N/A
2020년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by