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

1 次查看(过去 30 天)
% 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?
  3 个评论

请先登录,再进行评论。

回答(1 个)

Srivardhan Gadila
Srivardhan Gadila 2020-4-10
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.

类别

Help CenterFile Exchange 中查找有关 Time Series Objects 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by