Exporting figure keeping in given pixel size
8 views (last 30 days)
Show older comments
I want to save my figure in tiff format with given dimensions i.e 2464 * 2056 pixels.
However, when I use saveas(gcf,['locationr' num2str(j) '.tif']); I get this error ie
Error using print (line 83):
Unable to create output using specified size and resolution. Specify a smaller value for the PaperPosition
property of the figure or specify a smaller resolution value.
My code is as follows:
figure;
xlim([0 2500]);
ylim([0 2056]);
set(gca,'YDir','reverse');
set(gca,'Units','normalized','Position',[0 0 1 1]);
rez = [r c]; %set desired [horizontal vertical] resolution
set(gcf,'PaperPosition',[0 0 rez]);
hold on; x1=[]; y1=[]; x2=[]; y2=[]; u=[]; v=[];
x1=D4(:,1)
y1=D4(:,2)
x2=D4(:,3)
y2=D4(:,4)
u=x2-x1;
v=y2-y1;
q = quiver(x1,y1,u,v,'k', 'linewidth',5);
q.ShowArrowHead = 'off';
q.Marker = 'none';
saveas(gcf,['location' num2str(j) '.tif']);
Accepted Answer
Askic V
on 9 Dec 2022
The preferred way to save figures is to use builtin function called exportgraphics
Usually, if you need finer/better resolution for printing you specify DPI (dots per inch).
Please have a look at the following code:
figure;
xlim([0 2500]);
ylim([0 2056]);
set(gca,'YDir','reverse');
set(gca,'Units','normalized','Position',[0 0 1 1]);
hold on; x1=[]; y1=[]; x2=[]; y2=[]; u=[]; v=[];
x1=D4(:,1)
y1=D4(:,2)
x2=D4(:,3)
y2=D4(:,4)
u=x2-x1;
v=y2-y1;
q = quiver(x1,y1,u,v,'k', 'linewidth',5);
q.ShowArrowHead = 'off';
q.Marker = 'none';
% The preferred way is to use exportgraphics
exportgraphics(gcf,'test.tiff','Resolution',600)
In my case, it will produce test.tiff image with a resolution of 3501x2626
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!