【问题标题】:Fast way of exporting the same figure n-times导出相同图形 n 次的快速方法
【发布时间】:2017-03-03 13:15:47
【问题描述】:

我正在尝试在 matlab 中制作动画。为此,我正在展示包含动画中当前正在发生的事情的描述的图片。所以我正在写出我的数字的图片,然后再次使用 matlab 将这些图片放在一个 avi 文件中。为了使描述部分“显示”足够长,我使用了一个简单的循环,其中当前图形被保存 n 次。不幸的是,这个过程虽然 matlab 不需要计算任何新的东西,但却是最慢的一个。 作为循环,我使用以下内容(h_f 是图形句柄):

for delay = 1:80 
export_fig (h_f,['-r' num2str(resolution)], ['C:\Users\Folder\Name_', '_' num2str(7700+delay) '.png']) 
end

我只想问有没有更快的方法。现在感觉就像matlab每次在导出之前都会重新绘制无花果。那么有没有一种方法可以将图形绘制一次并同时导出 n 次?

感谢您的帮助:)

【问题讨论】:

    标签: matlab export figure


    【解决方案1】:

    如果它们都完全相同,那么您可以将第一个文件复制到后续文件中。您的时间将受到磁盘驱动器速度和图像文件大小的限制。

    % Define some of the flags as variables. This'll make it clearer
    % what you're doing when you revisit the code in a year.
    
    % Flag for the resolution
    resFlag = sprintf('-r%u', resolutions);
    
    % Base folder
    folder = 'C:\Users\Folder\';
    
    % First file number
    startnum = 7701;
    
    % This is the pattern all the filenames will use
    nameToken = 'Name_%u.png';
    
    % First filename
    firstFile = fullfile(folder, sprintf(nameToken, startnum));
    
    % Export the first file
    export_fig(h_f, resFlag, firstFile);
    
    numCopies = 80;
    
    % Copy the file
    for delay = 2:numCopies 
        % Make a new filename
        currentFile = fullfile(folder, sprintf(nameToken, startnum + delay));
    
        % Copy the first file into the current filename.
        copyfile(firstFile, currentFile);
    end
    

    【讨论】:

    • 非常感谢,这真的为我节省了不少时间! :)
    猜你喜欢
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2011-05-10
    • 2012-09-01
    • 2016-01-26
    • 1970-01-01
    相关资源
    最近更新 更多