How can multiple plots be combined into one figure in M…
In MATLAB, multiple plots can be combined into one using the subplot function. The syntax of the subplot function is as follows:
Arrange m by n plots in an array and select the p-th subplot.
m represents dividing the graph into m rows, n represents dividing the graph into n columns, and p represents the position of the current subplot. When merging multiple plots into one, the subplot function can be used to set the positions of different subplots as needed.
Here is an example code that combines two images into one.
% 创建数据
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = cos(x);
% 创建画布
figure;
% 第一个子图
subplot(2, 1, 1);
plot(x, y1);
title('sin(x)');
% 第二个子图
subplot(2, 1, 2);
plot(x, y2);
title('cos(x)');
By running the above code, you can combine the graphs of y1 and y2 into one graph, with a title labeled above each subplot.