Matlab:打开以前保存的数字并另存为

Posted

技术标签:

【中文标题】Matlab:打开以前保存的数字并另存为【英文标题】:Matlab : Open previously saved figures and save as 【发布时间】:2016-11-08 17:17:58 【问题描述】:

我正在编写一个 Matlab 代码,它将图形绘制并保存为 png 和 eps。

h = figure(3);
    plot(x,y)
    xlabel('x'); ylabel('y');

        FileName = sprintf('FileName.eps');
        print(h,'-depsc', '-loose', FileName);

        FileName = sprintf('FileName.png);
        print(clhis,'-dpng', '-loose', FileName);

close(h)

我只想将它们保存为 FileName.fig 以供以后处理。 我想创建的函数/脚本将读取当前目录中的所有 *.fig 并将它们保存为定义的函数。

这是一个伪函数……但我不知道如何使它正常工作!

function figureconvert(ext)    % NOT WORKING! Just a mock up!
ext = 'eps';        

Vector = READ ALL FIGS IN FOLDER;

for i = 1:length(Vector)
h = load Vector(i)

            FileName = sprintf('FileName.%s',ext);
            % print(h,'-d%sc', '-loose', FileName); ??

    close(h)
end
end

【问题讨论】:

在关闭它之前做savefig(h,'myname.fig') 【参考方案1】:

我找到了解决方法。如果其他人需要这样的功能,这是我的功能。

只写:

 figureconvert('png')   or     figureconvert('eps')

将 *.fig 分别转换为 *.png 或 *.eps。

function figureconvert(ext)
Files = dir('*.fig');
ext = ['.',ext]; ext = strrep(ext,'..','.');

for i = 1:length(Files)
    figname = Files(i,1).name;
    h = openfig(figname);
    FigName = strrep(figname,'.fig',ext);

    if strcmp(ext,'.eps')
        print(h,'-depsc', '-loose', FigName);
    elseif strcmp(ext,'.png')
        print(h,'-dpng', '-loose', FigName);
    end

    close(h)
end
end

【讨论】:

以上是关于Matlab:打开以前保存的数字并另存为的主要内容,如果未能解决你的问题,请参考以下文章

打开 Excel 文件并另存为 .XLS

Python打开网页并另存为静态html怎么实现

Photoshop - 增加文本中的数字并另存为该文本

提示用户打开工作簿并另存为新工作簿

强制“是”以保存并另存为无宏工作簿

生成 div 的图像并另存为