2017-05-10 73 views
0

我已經查找了關於在Matlab中打印圖形的這個簡單問題,但迄今尚未成功。我有這種類型的一個for循環:如何在Matlab中使用帶循環的打印命令

N = 5; 
for sim = 1:10 
    X = randn(sim,N); 
    X = mean(X); 

    figure; 
    plot(X); 
    print -depsc X; 
end 

我想打印和保存一個新的圖表爲每個模擬,並自動命名,例如,X1爲SIM = 1,X2爲SIM = 2, X3 for sim = 3等。我該怎麼做?

回答

1

試試這個:

N = 5; 
for sim = 1:10 
    X = randn(sim,N); 
    X = mean(X); 

    hFig = figure; 
    plot(X); 

    % create filename and print to eps 
    filename = strcat('X',num2str(sim)); 
    print(hFig,filename,'-depsc'); 
end 

希望這有助於!

+0

太好了,謝謝! – LenaH