Question

I have a code that is creating and capturing a jpg file. However, it tends to come out with two different image sizes. This becomes a problem when I want to make the jpg files into a movie. I have set PaperPosition and a few other things as well, but it still comes out with two image sizes. The image size change seems random since if I run the code twice, an image that had one of the sizes before could have the other size now.

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)

How can I set the image size (hopefully to full screen like I tried to do in set(ax, ...) so that when I save the jpg files, they are all the same size?

Était-ce utile?

La solution

You can simply resize the image to whatever size you want, so you know it will be constant.

B = imresize(A, [numrows numcols])

Look at the imresize documentation if you have other particular questions about it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top