How can I resize a plot image and save it?

2 ビュー (過去 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:

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by