MATLAB图可见关闭

时间:2014-05-03 00:38:17

标签: matlab figure

我试图从MATLAB保存.jpg文件,但我不想每次都弹出这个数字,因为这真的会减慢这个过程。但是,设置'可见'到'关闭'似乎不起作用。如何让图窗口不弹出?

nFrames = 2557; % Number of frames. Number of days between 1/1/2008 and 1/31/2014
for k = 183:nFrames % 183 (7/1/2008) to the number of days. Data before this is either missing or from HI 
    % 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_PM25{k}), str2double(Lon_PM25{k}), 40, str2double(data_PM25{k}), 'filled'); % Plot a dot at each Lat and Lon with black outline around each dot (helps show dots that are too low for it to be colored by the color bar
        % Draw outline around dot with 'MarkerEdgeColor', [0.5 0.5 0.5] for gray
    hold on

    % Colorbar
    caxis([5 30]);
    h = colorbar;
    ylabel(h,'ug/m3');

    % Title
    % date = datenum(2007, 04, 29) + k; % Convert t into serial numbers.
    title(['PM2.5 24-hr Block Average Concentration ', datestr(cell2mat(date_PM25(k)), 'mmm dd yyyy')]); % Title changes every day;

    % Capture the frame
    mov(k) = getframe(gcf);

    % Set size of paper
    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_PM25(k)),'yyyy_mm_dd') '_PM25_24hrBlkAvg.jpg']);

    clf
end

1 个答案:

答案 0 :(得分:2)

问题在于getframe。这个threadthis discussion中给出了详细的答案。 简而言之,您需要避免使用getframe,而是执行以下操作:

    ax = figure(1); 
    set(ax, 'visible', 'off')
    set(ax, 'PaperPositionMode','auto')
    aviobj = avifile('file.avi');
    ....


   for k=1:N
      %# all the plotting you did before the getframe
      img = hardcopy(ax, '-dzbuffer', '-r0');
      aviobj = addframe(aviobj, im2frame(img));
   end

   aviobj = close(aviobj);