Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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 Ansicht (letzte 30 Tage)
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.

Antworten (1)

Gaurav Garg
Gaurav Garg am 18 Nov. 2019
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