【MATLAB】将多个图像输出到单个图形窗口上:使用 subplot 函数创建子图

引言

subplot是MATLAB中的一个函数,它用于在单个图形窗口中创建多个子图。这对于同时显示多个图形或图像非常有用。


语法详解

基本语法:

matlab 复制代码
subplot(m, n, p)

参数详解:

  • m 指定图形窗口应该分割成多少行
  • n 指定图形窗口应该分割成多少列
  • p 指定当前活动的是哪个子图

注意事项

subplot函数会自动管理活动子图的切换。当你调用subplot(m, n, p)时,它会使子图p成为当前活动的子图,任何后续的绘图命令都会在这个子图上执行,直到你再次调用subplot切换到其他子图。


举个例子

在一个2x2的子图中绘制四个不同的图形:

matlab 复制代码
% read image
I = imread('cameraman.tif');
figure,imshow(I); title('Original image');

figure;

% maketform and imtransform
x = pi / 3;
T = [cos(x), sin(x), 0; -sin(x), cos(x), 0; 0, 0, 1];
tform = maketform('affine', T);
I1 = imtransform(I, tform);
subplot(2, 2, 1); imshow(I1); title('maketform and imtransform');
imwrite(I1,'cameraman_rotated_1.jpg');

deg = 60;

% nearest neighborhood
I2 = imrotate(I, deg, "nearest");
subplot(2, 2, 2); imshow(I2); title('imrotate, nearest');
imwrite(I2,'cameraman_rotated_2.jpg');

% bilinear
I3 = imrotate(I, deg, "bilinear");
subplot(2, 2, 3); imshow(I3); title('imrotate, bilinear');
imwrite(I3,'cameraman_rotated_3.jpg');

% bicubic
I4 = imrotate(I, deg, "bicubic");
subplot(2, 2, 4); imshow(I4); title('imrotate, bicubic');
imwrite(I1,'cameraman_rotated_4.jpg');
相关推荐
郝学胜-神的一滴4 小时前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy
不积跬步无以至千里mmbb264 小时前
【软件工艺师 rust相关课程】
开发语言·后端·rust
SEO_juper4 小时前
HTTPS 混合内容检查工具:页面全站 https 了,但还有 http 资源在拖后腿
开发语言·网络协议·http·https·node.js·json·bash
神一样的老师6 小时前
WS63 BLE 配网实战:用 Python 在 PC 上替代手机完成 WiFi 配网
开发语言·python·智能手机
geovindu7 小时前
python: Decision Tree
开发语言·后端·python·决策树
时间的情敌7 小时前
Three.js 工业场景性能优化合集|大批量管线、InstancedMesh 实例化、合并 Geometry、显存释放
开发语言·javascript·性能优化·three.js
步峰代理-盾山8 小时前
R语言爬虫实战:使用httr与XML解析网页数据并进行统计分析
xml·开发语言·爬虫·r语言·网络爬虫
sharemylove18 小时前
Java集合框架全面详解
java·开发语言·经验分享·笔记·学习
郝学胜-神的一滴1 天前
Effective Python 条款43:自定义容器类
开发语言·windows·python·pandas·scikit-learn·pyqt
好焊孙辉1 天前
一条产线省下 30 个电机位:Z 轴和 R 轴,该合成一个了
开发语言·r语言