【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');
相关推荐
tung tung tung sahur1 天前
领略 Rust 抽象之美:自定义迭代器实现全解析
开发语言·后端·rust
ftpeak1 天前
《Rust MP4视频技术开发》第八章:生成MP4
开发语言·rust·音视频·mp4
好学且牛逼的马1 天前
【SSM框架 | day25 spring IOC 与 DI 注解开发】
java·开发语言
_OP_CHEN1 天前
C++进阶:(四)set系列容器的全面指南
开发语言·c++·stl·set·multiset·关联式容器·setoj题
不惑_1 天前
Java 使用 FileOutputStream 写 Excel 文件不落盘?
开发语言·python
十五年专注C++开发1 天前
Qt-VLC: 一个集成VLC的开源跨平台媒体播放库
开发语言·qt·媒体·libvlc·vlc-qt
郝学胜-神的一滴1 天前
128天写作之旅:记录与成长的点滴
开发语言·程序人生
superman超哥1 天前
仓颉语言中流式I/O的设计模式深度剖析
开发语言·后端·设计模式·仓颉
豆浆whisky1 天前
Go内存管理最佳实践:提升性能的Do‘s与Don‘ts|Go语言进阶(17)
开发语言·后端·golang
Kay_Liang1 天前
Spring中@Controller与@RestController核心解析
java·开发语言·spring boot·后端·spring·mvc·注解