필터 지우기
필터 지우기

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

조회 수: 2 (최근 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에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by