Reputation: 6494
I'm trying for hours to simply output a certain plot in a specific resolution (320x240).
xmax = 320; ymax = 240;
xmin = 0; ymin = 0;
figure;
set(gcf,'position',[1060 860 320 240]);
axis([xmin,xmax,ymin,ymax]);
plot(someLinesAndPointsInTheRange320X240);
saveas(gca,outName,'jpg');
export_fig(outName);
Where saveas
output the jpg image in an arbitrary resolution. export_fig
is still showing the axes.
Adding an axis off
or axis tight
doesn't help either.
Has anyone an idea?
UPDATE:
The problem is solved. Just for completeness here is my current solution:
xmax = 320; ymax = 240;
xmin = 0; ymin = 0;
figure;
set(gcf,'position',[1060 860 320 240]);
subaxis(1,1,1, 'Spacing', 0.01, 'Padding', 0, 'Margin', 0); % Removes padding
axis([xmin,xmax,ymin,ymax]);
plot(someLinesAndPointsInTheRange320X240);
axis([xmin,xmax,ymin,ymax]);
set(gca,'xtick',[],'ytick',[]); % Removes axis notation
I = frame2im(getframe(gcf)); %Convert plot to image (true color RGB matrix).
J = imresize(I, [240, 320], 'bicubic'); %Resize image to resolution 320x240
imwrite(J, 'outName.jpg'); %Save image to file
Upvotes: 3
Views: 1826
Reputation: 1
There's an easier solution for this.
Saying you have your figure, gcf, you capture the frame and just use imresize to edit the object property cdata of your frame.
frame = getframe(gcf);
frame.cdata = imresize(frame.cdata,[240, 320]);
Then you can write your video using this frame, which now has the assigned resolution.
writeVideo(VideoObj,frame);
It works quite well.
Upvotes: 0
Reputation: 32084
Possible solution is converting figure to image, and use imresize
.
Fixing the figure position to match 320x240 resolution is possible, but using imresize
is simpler (I think).
The following code sample, convert figure to image, and use imrezie
to set resolution to 320x240:
figure;
% xmax = 320; ymax = 240;
% xmin = 0; ymin = 0;
% set(gcf,'position',[1060 860 320 240]);
% axis([xmin,xmax,ymin,ymax]);
plot(sin(-pi:0.01:pi)); %Example figure
I = frame2im(getframe(gcf)); %Convert plot to image (true color RGB matrix).
J = imresize(I, [240, 320], 'bicubic'); %Resize image to resolution 320x240
imwrite(J, 'J.jpg'); %Save image to file
Upvotes: 3