how do i print multiple bar graphs in a single window in matlab

To print multiple bar graphs in a single window in Matlab, you can make use of the subplot function to create multiple axes in a single figure. Here's an example code snippet which generates two bar graphs side by side in a single window:

main.m
x1 = [1 2 3 4 5];
y1 = [10 24 13 18 32];

x2 = [1 2 3 4 5];
y2 = [24 15 28 20 12];

figure;
subplot(1, 2, 1);
bar(x1, y1);
title('Bar graph 1');

subplot(1, 2, 2);
bar(x2, y2);
title('Bar graph 2');
199 chars
15 lines

In the above code, subplot(1, 2, 1) creates an axis in the first column of a 1 row and 2 column grid, and subplot(1, 2, 2) creates another axis in the second column of the same grid. Finally, bar function is used to create a bar graph in each of the two axes.

related categories

gistlibby LogSnag