我有一个创建和捕获jpg文件的代码。但是,它往往会出现两种不同的图像尺寸。当我想将jpg文件变成电影时,这就成了问题。我也设置了PaperPosition
和其他一些东西,但它仍然有两个图像尺寸。图像大小的变化似乎是随机的,因为如果我运行代码两次,那么之前具有其中一个尺寸的图像现在可以具有另一个尺寸。
nFrames = 8797; % Number of frames. Number of days between 1/1/1990 and 1/31/2014
for k = 1:nFrames % 1/1/1990 to the number of days.
% Map of conterminous US
ax = figure(1);
set(ax, 'visible', 'off', 'units','normalized','outerposition',[0 0 1 1]); % Make window that shows up full sized, which makes saved figure clearer
ax = usamap('conus');
states = shaperead('usastatelo', 'UseGeoCoords', true,...
'Selector',...
{@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
faceColors = makesymbolspec('Polygon',...
{'INDEX', [1 numel(states)], 'FaceColor', 'none'}); % NOTE - colors are random
geoshow(ax, states, 'DisplayType', 'polygon', ...
'SymbolSpec', faceColors)
framem off; gridm off; mlabel off; plabel off
hold on
% Plot data
scatterm(ax,str2double(Lat_O3{k}), str2double(Lon_O3{k}), 40, str2double(data_O3{k})*1000, 'filled'); % Plot a dot at each Lat and Lon
hold on
% Colorbar
caxis([10 90]);
h = colorbar;
ylabel(h,'ppb');
% Title
% date = datenum(2007, 04, 29) + k; % Convert t into serial numbers.
title(['O3 MDA8 Concentration ', datestr(cell2mat(date_O3(k)), 'mmm dd yyyy')]); % Title changes every daytitle(str);
% Capture the frame
mov(k) = getframe(gcf); % Makes figure window pop up
% Set size of image
set(gcf,'Units','points')
set(gcf,'PaperUnits','points')
size = get(gcf,'Position');
size = size(3:4);
set(gcf,'PaperSize',size)
set(gcf,'PaperPosition',[0,0,size(1),size(2)])
% Save as jpg (just specify other format as necessary) - Must set 'facecolor' to 'none' or else color of states turn out black
eval(['print -djpeg map_US_' datestr(cell2mat(date_O3(k)),'yyyy_mm_dd') '_O3_MDA8.jpg']);
% saveas(gca, ['WI_' datestr(cell2mat(Date)) '_PM25.jpg']);
clf
end
% Save as AVI file - Set 'facecolor' to 'white'. It looks better.
close(gcf)
如何设置图像大小(希望像我在set(ax, ...)
中尝试的那样全屏显示,这样当我保存jpg文件时,它们的大小都相同?
答案 0 :(得分:0)