How can I resize a plot image and save it?
2 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Devineni Aslesha
on 10 Sep 2019
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:
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!