2016-11-08 90 views
0

我正在寫一個繪製並保存數字爲PNG和EPS的Matlab代碼。Matlab:打開先前保存的數字並保存爲

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

在關閉它之前,執行'savefig(h,'myname.fig')' –

回答

0

我發現一個解決方案如何做到這一點。這是我的功能,如果別人需要這樣的功能。

只要寫:

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