2013-09-30 59 views
3

for循環中,我創建了可變數量的子圖,這些子圖顯示在一個圖上。我是否也可以將每個子圖保存爲單獨的全尺寸圖和圖像文件(最好是JPG)?Matlab將個別子圖保存爲jpg

回答

2

使用copyobj到一個新的人物,然後使用新數字手柄另存爲:

,你應該有提供

示例代碼(見SSCCE):

figure 
nLines = 2; 
nColumns = 3; 
handles = zeros(nLines,nColumns) 
for line = 1:nLines 
    for column = 1:nColumns 
    handles(line,column)=subplot(nLines,nColumns,column+(line-1)*nColumns); 
    plot([line column]); 
    title(sprintf('Cool title (%d,%d)',line,column)) 
    ylabel(sprintf('Ylabel yeah (%d,%d)',line,column)) 
    xlabel(sprintf('Xlabel nah (%d,%d)',line,column)) 
    end 
end 

在這裏,我的插曲句柄保存但假如你沒有他們保存:

axesH = findobj(gcf,'Type','axes','-not','Tag','legend'); % This will change the order from which the axes will be saved. If you need to save in the correct order, you will need access to the subplot handles 
nAxes = numel(axesH) 
newFig = figure; 
for k=1:nAxes 
    newAxes=copyobj(axesH(k),newFig); 
    % Expand subplot to occupy the hole figure: 
    set(newAxes,'OuterPosition',[0 0 1 1]); 
    tightInset=get(newAxes,'TightInset'); 
    set(newAxes,'Position',[tightInset(1:2) [1 1]-(tightInset(3:4)+tightInset(1:2))]) 
    saveas(newFig,sprintf('axes_%d.jpg',k),'jpg'); 
    delete(newAxes); 
end 
delete(newFig); 

例一中軸線保存:

One subplot example

要刪除死區,我使用了可用的信息on this topic

+0

謝謝華納。我最終得到了一個獨立的副圖和色彩映射文件。我給了你一個綠色的勾號,告訴我如何列舉一個人物上的物體。我會繼續研究它。 – user1502755

+0

@ user1502755我無法得知子圖和顏色表的問題。如果您從您正在使用的次要情節中提供SSCCE,以及​​如何重現您遇到的問題,我可以幫助您。 – Werner

1

說你有句柄subfigure的軸,ha,您可以使用getframeframe2im如下,

F = getframe(ha); 
[im,map] = frame2im(F); 
if isempty(map) 
    imwrite(im,'subframe.jpg'); 
else 
    imwrite(im,map,'subframe.jpg'); 
end 

注意,這將節省軸究竟它是如何出現在屏幕上,因此請在保存前根據自己的喜好調整圖形大小。要儘可能多地使用數字地圖,請在MATLAB Central上試用subfigure_tight函數。

+0

謝謝chappjc。它像廣告一樣,不幸的是我的框架返回空的顏色映射。我會繼續研究它。我給了你一個有用的點擊。 – user1502755

+0

你的意思是顏色**欄**? – chappjc