matlab 保存图片的几种方式

matlab 保存图片的几种方式

最近在写毕业论文, 需要保存一些高分辨率的图片. 下面介绍几种MATLAB保存图片的 方式.

一. 直接使用MATLAB的保存按键来保存成各种格式的图片

你可以选择保存成各种格式的图片, 实际上对于一般的图片要求而言, 该方法已经足够了.

二. 使用saveas函数

该函数实际上类似于 “另存为” 的选项, 并且忽略图片的背景大小等等, 按照默认的属性存储.

一般格式为为

saveas(fig, filename, formattype)

clear

clc

x = 0:0.01:2*pi;

y = sin(x);

plot(x, y)

xlabel('x')

ylabel('y')

title('y = Sin(x)')

saveas(gcf, 'test', 'png')

这的可选项有png, jpg, bmp等等, 以及矢量图格式, eps, svg, pdf等等.

三. 使用imwrite函数

imwrite 实际上是保存一个描述图片的数组, 使用的一般格式为imwrite(A, filename)

clear

clc

x = 0:0.01:2*pi;

y = sin(x);

plot(x, y)

xlabel('x')

ylabel('y')

title('y = Sin(x)')

f = getframe(gcf);

imwrite(f.cdata, 'test.png');

该函数可以用于保存为png, jpg, bmp等等格式, 但是不可以保存为eps, svg, pdf 等矢量图格式.

该函数还可以用于保存gif.

clear

clc

n = 1:10;

nImages = length(n);

x = 0:0.01:1;

im = cell{nImages, 1};

figure;

for idx = 1:nImages

y = sin(2*pi*x*idx);

plot(x,y,'LineWidth',3)

title(['y = sin(2n\pix), n = ' num2str(n(idx)) ])

drawnow

frame = getframe(gcf);

im{idx} = frame.cdata;

end

close;

filename = 'test.gif';

for idx = 1:nImages

[A,map] = rgb2ind(im{idx},256);

if idx == 1

imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',1);

else

imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',1);

end

end

四. 使用 printf 函数

clear

clc

x = 0:0.01:2*pi;

y = sin(x);

plot(x, y)

xlabel('x')

ylabel('y')

title('y = Sin(x)')

printf(gcf,'-dpng','test.png')

相关推荐

《文明6》伟人怎么用?
365bet网络娱乐

《文明6》伟人怎么用?

📅 10-03 👁️ 4059
海绵宝宝里有哪些地名(海绵宝宝里有哪些地名名字)
365足球体育亚洲版

海绵宝宝里有哪些地名(海绵宝宝里有哪些地名名字)

📅 06-27 👁️ 8148
形容有关闹钟的成语大全
365足球体育亚洲版

形容有关闹钟的成语大全

📅 10-29 👁️ 5654
揭秘灵石108服务区:那些你不可不知的快餐美食秘密
365足球体育亚洲版

揭秘灵石108服务区:那些你不可不知的快餐美食秘密

📅 02-20 👁️ 889
微博怎么批量取消关注?一步搞定,轻松管理你的关注列表
iPad Air 5价格大跳水!4715元入手超值体验
365足球体育亚洲版

iPad Air 5价格大跳水!4715元入手超值体验

📅 09-30 👁️ 3690
保卫萝卜3官方正版
365足球体育亚洲版

保卫萝卜3官方正版

📅 12-31 👁️ 3970
银行贷款10万全流程解析:申请条件、材料清单及注意事项
如何在 iPhone 或 iPad 上使用 iCloud 共享照片图库
365bet线上足球

如何在 iPhone 或 iPad 上使用 iCloud 共享照片图库

📅 09-27 👁️ 2700