【问题标题】:MATLAB Figure Visible OffMATLAB 图可见关闭
【发布时间】:2014-06-19 18:35:05
【问题描述】:

我正在尝试从 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

【问题讨论】:

  • 你试过ax = figure('Visible','off');
  • 是的。我已经有set(ax, 'visible', 'off', 'units','normalized','outerposition',[0 0 1 1]),它仍然会弹出一个窗口。在此之前我尝试了ax = figure('Visible','off');,但仍然弹出窗口。我在scatterm 之前尝试过它,这给了我一个关于它不是地图轴的错误。
  • 按照我在使用set等之前写的方式尝试...
  • 我试过了。图仍然弹出。

标签: matlab figure


【解决方案1】:

问题在于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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    相关资源
    最近更新 更多