在MATLAB中,可以使用figure和subplot函数来输出多个图像。
- 使用figure函数创建一个新的图像窗口。
figure;
- 使用subplot函数将图像窗口分割为多个子图,并选择要输出的子图。
subplot(m, n, p);
其中,m和n分别表示子图的行数和列数,p表示当前子图的位置。例如,如果要输出一个2×2的子图中的第一个子图,可以使用subplot(2, 2, 1)。
- 在每个子图中绘制图像。
imshow(image);
其中,image表示要绘制的图像。
下面是一个完整的示例代码:
% 读取图像 image1 = imread('image1.jpg'); image2 = imread('image2.jpg'); % 创建图像窗口 figure; % 第一个子图 subplot(1, 2, 1); imshow(image1); title('Image 1'); % 第二个子图 subplot(1, 2, 2); imshow(image2); title('Image 2');
这样就会在一个图像窗口中输出两个图像。