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

1 回表示 (過去 30 日間)
N/A
N/A 2020 年 4 月 4 日
コメント済み: N/A 2020 年 4 月 10 日
% 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 件のコメント
N/A
N/A 2020 年 4 月 10 日
Yes that's correct d=dates

サインインしてコメントする。

回答 (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 Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by