Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to obtain all the bar graphs. My code only gives one bar graph even though I have written a code to get four bar graphs.

조회 수: 1 (최근 30일)
I have to plot four different bar graphs, and for each I am forming a matrix and then subsequently plotting it. The output shows only one bar graph, the other three are missing. Below is a picture of that portion of the code.
It's showing bar graph only for the last matrix, i.e., the one for which code lines 368 to 375 are dedicated.
I want all the bar graphs to come out as different figures in the output. Please help.

답변 (1개)

Gaurav Garg
Gaurav Garg 2019년 11월 18일
Hi,
bar(y) creates a bar graph with one bar for each element in y. In your case, you plot the bars on top of each other and hence, you see the bar graph only for the last matrix/data.
However, if y is an m-by-n matrix, then bar creates m groups of n bars.
So, you can choose to append the matrices in a single matrix and plot bar for the resultant matrix.
An example -
y1=[1:4];
y2=[5:8];
y3=[9:12];
x=[1:4];
bar(x,[y1;y2;y3]');

Community Treasure Hunt

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

Start Hunting!

Translated by