필터 지우기
필터 지우기

Is it possible to obtain both line and bars on the same graph?

조회 수: 1 (최근 30일)
Pietro Fiondella
Pietro Fiondella 2022년 6월 28일
댓글: Star Strider 2022년 6월 28일
I have these vectors Years, A,B i would like to obtain a single graph with both bar(Years,B) and plot(Years,A).
How can i do this?
Years=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
A=[-8.8000 -8.5211 -8.2421 -7.9632 -7.6843 -7.4053 -7.1264 -6.8475 -6.5685 -6.2896 -6.0107 -5.7318 -5.4528 -5.1739 -4.8950 -4.6160 -4.3371 -4.0582 -3.7792 -3.5003 -3.2214];
B=[-8.8000 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189];
%I can obtain separatly graphs:
plot(Years,A);
bar(Years,B);

채택된 답변

Star Strider
Star Strider 2022년 6월 28일
Use the hold function
Years=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
A=[-8.8000 -8.5211 -8.2421 -7.9632 -7.6843 -7.4053 -7.1264 -6.8475 -6.5685 -6.2896 -6.0107 -5.7318 -5.4528 -5.1739 -4.8950 -4.6160 -4.3371 -4.0582 -3.7792 -3.5003 -3.2214];
B=[-8.8000 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 1.1589 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189 0.7189];
%I can obtain separatly graphs:
figure
plot(Years,A)
hold on
bar(Years,B)
hold off
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by