2014-05-03 142 views
2

我试图从MATLAB保存.jpg文件,但我不想每次都弹出图形,因为这确实会减慢过程。但是,将“可见”设置为“关闭”似乎不起作用。我能做些什么来让图窗口不弹出?MATLAB Figure Visible Off

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 
+0

你尝试'AX =图(“可见”,“关闭”);' – bla

+0

是。我已经有'set(ax,'visible','off','units','normalized','outerposition',[0 0 1 1])',这仍然会弹出一个窗口。我尝试过'ax = figure('Visible','off');'就在这之前,窗户仍然弹出。我在'scatterm'之前尝试过了,这给了我一个关于它不是地图轴的错误。 – shizishan

+1

尝试一下我在使用'set'之前写下它的方式...... – bla

回答

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);