2010-10-24 11 views
10

में एक आकृति में गठबंधन करें मेरा प्रोग्राम कमांड चक्र के दौरान छोटे आंकड़े उत्पन्न करता है। क्या इन आंकड़ों को बचाने के लिए कोई तरीका है और फिर उन्हें बाद में एक आंकड़े में जोड़ना है?सबप्लॉट्स का निर्माण और फिर उन्हें बाद में MATLAB

उत्तर

17

कोड पर विचार करें:

hFig = figure; 

%# create temporary subplots as template 
for i=1:2, h(i) = subplot(2,1,i); end  %# create subplots 
pos = get(h, 'Position');     %# record their positions 
delete(h)         %# delete them 

%# load the .fig files inside the new figure 
fileNames = {'a.fig' 'b.fig'};    %# saved *.fig file names 
for i=1:2 
    %# load fig 
    hFigFile = hgload(fileNames{i}); 

    %# move/copy axis from old fig to new fig 
    hAx = get(hFigFile, 'Child');   %# hAx = gca; 
    set(hAx, 'Parent',hFig) 
    %#hAx = copyobj(hAx,hFig); 

    %# resize it to match subplot position 
    set(hAx, 'Position',pos{i}); 

    %# delete old fig 
    delete(hFigFile) 
end 

यह इस newsgroup discussion

+1

अद्भुत, वास्तव में वास्तव में अच्छा अपडेट किया है। बहुत बहुत धन्यवाद, यह बहुत दर्द बचाता है। – Vass

+0

और समाचार समूह चर्चा का लिंक उपयोगी है – Vass

1

saveas का उपयोग करें। अपने सबप्लॉट को एक FIG फ़ाइल के रूप में सहेजें ताकि आपके पास बाद में पूर्ण नियंत्रण हो (जैसा कि एक जेपीजी के विपरीत)।

एक टाइलिंग पैटर्न चुनें और फिर एक में एकाधिक आंकड़े प्रदर्शित करने के लिए subplot का उपयोग करें।

+0

आप उन्हें कैसे फिर एक ही आंकड़ा में लोड करते हैं? – Vass

+0

@ वास: मैंने अपना जवाब – Jacob

1

मैं एक जवाब यहाँ एक उदाहरण है:

h1 = figure(1) 
plot(1:10,'o-r'); 
title('title'); 
xlabel('xlabel'); 
ylabel('ylabel'); 

% Copy contents 
ch(1) = copyobj(gca,gcf); 

% Figure 2 
h2 = figure(2) 
plot(1:30,'o-r'); 
title('title fig2'); 
xlabel('xlabel'); 
ylabel('ylabel'); 
% copy contents 
ch(2) = copyobj(gca,gcf); 

figure(3) 
sh = subplot(1,2,1); 
clear axes 
p = get(sh,'position'); 
ah = copyobj(ch(1),gcf); 
set(ah,'position',p); 

% Create axis template 
sh = subplot(1,2,2); 
clear axes 
p = get(sh,'position'); 
ah = copyobj(ch(2),gcf); 
set(ah,'position',p); 

% Delete template 
% delete(sh); 
1

Amro's solution कार्यों से बहुत अनुकूलित किया गया था, लेकिन boxplots साथ आप Xtick और Xtick लेबल को रीसेट करने के लिए, अन्यथा, किसी कारण से, वे सबप्लॉट के अनुसार आकार में नहीं बदला जाएगा। जब आप boxplot या आंकड़ा ऐड खोलने के बाद बनाने के लिए:

set(gca,'XTick',<1d vector>,'XTickLabel',<1d cell vector>) 

या स्वचालित टिक डाल दिया और लेबल

set(gca,'XTickMode','auto','XTickLabelMode','auto') 
+0

दिलचस्प, साझा करने के लिए धन्यवाद। क्या आपने कुल्हाड़ियों को स्थानांतरित करने की बजाय प्रतिलिपि बनाने का प्रयास किया था (मेरे कोड में टिप्पणी की गई पंक्ति)? ईमानदार होने के लिए मेरा समाधान त्रुटियों के बिना नहीं है; उदाहरण के लिए यदि यह आंकड़े अलग-अलग रंगमंच होते हैं (जब तक आप [अतिरिक्त प्रयास] नहीं लेते हैं (http://www.mathworks.com/support/solutions/en/data/1-GNRWEH/index.html) को काम करने के लिए उस) – Amro

संबंधित मुद्दे