two graphs one figure in matlab

To plot two graphs in one figure using MATLAB, we can make use of the subplot function. Here's an example of how to use subplot:

main.m
%Create sample data
x1 = [1:10];
y1 = sin(x1);

x2 = [1:10];
y2 = cos(x2);

%Create figure and set its size
figure('Position', [100 100 800 400]);

%Create two subplots, one on top and one on bottom
subplot(2,1,1);
plot(x1, y1);
title('Graph 1');

subplot(2,1,2);
plot(x2, y2);
title('Graph 2');
296 chars
19 lines

In this example, we first create some sample data for two graphs. We then create a figure, setting its size using the 'Position' property. Finally, we use subplot to create two subplots, one on top and one on bottom. In each subplot we plot one of our sample graphs using the plot function, and add titles to each subplot using the title function.

Running this code should result in a figure with two graphs, one on top and one on bottom.

gistlibby LogSnag