How can I resize a plot image and save it?

2 次查看(过去 30 天)
Hi guys,
How can i resize a plotted graph to a certain image size before saving it?
I currently need a 32 by 32 pixel image file and I am only successful in creating the plot thus far as shown below. And would it be possible also to convert it in to a image file of 32x32x1 size too?
Please help me, many thanks in advance!
x=0:0.01:randi(10);
img1 = figure;
fxs = {sin(x),x.^2,x.^3};
y=fxs{randi(3)};
plot(x,y,'w');
set(gcf,'color','k');
set(gca,'Color','k')
camroll(randi(360));
baseFileName = sprintf('CL %d.png',i);
fullFileName = fullfile('Curves', baseFileName);
export_fig(fullFileName);

回答(1 个)

Devineni Aslesha
Devineni Aslesha 2019-9-10
Assuming the resolution of image to be 32*32 pixels, the image is saved in the specified resolution and format using print function in MATLAB.
x=0:0.01:randi(10);
img1 = figure;
fxs = {sin(x),x.^2,x.^3};
y=fxs{randi(3)};
plot(x,y,'w');
set(gcf,'color','k');
set(gca,'Color','k');
camroll(randi(360));
print('Curves','-dpng','-r100');
This print function saves the image with a resolution of 125*33 pixels as its resolution is set as 100 dpi. However, the image is not obtained as a square image by changing the resolution in dpi.
Doc Link:

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by