Clear Filters
Clear Filters

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

2 views (last 30 days)
% 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 Comments

Sign in to comment.

Answers (1)

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

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!