How can I resize a plot image and save it?

조회 수: 4 (최근 30일)
Joon Yong Chu
Joon Yong Chu 2019년 9월 7일
답변: Devineni Aslesha 2019년 9월 10일
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:

Community Treasure Hunt

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

Start Hunting!

Translated by