Please help! Combine figures into one new figure

조회 수: 2 (최근 30일)
Deniz Baturay
Deniz Baturay 2016년 3월 24일
편집: Deniz Baturay 2016년 3월 27일
I obtained many figures like the figure.
In every figure, I have two graphs. I want to take left graphs from every figure and combine them into one new figure. Also, I want to take right graphs from every figure and combine them into one new figure. Graphs have legends, xlabel and ylabel.
  댓글 수: 2
KSSV
KSSV 2016년 3월 24일
편집: KSSV 2016년 3월 24일
what format the figures are in? If .fig (Matlab fig) attempt is easy.
Deniz Baturay
Deniz Baturay 2016년 3월 24일
They are in .fig format but as you see graphs have bolded xlabel, ylabel and legends.

댓글을 달려면 로그인하십시오.

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 24일
편집: Azzi Abdelmalek 2016년 3월 25일
Edit
%---------------------Generate an example---------------------------------
t=0.1:0.1:10;
y=rand(numel(t),6);
for k=1:2:5
figure
subplot(1,2,1)
plot(t,y(:,k))
legend(sprintf('leg%d',k))
title(gca,sprintf('title%d',k))
xlabel(gca,sprintf('x%d',k))
ylabel(gca,sprintf('y%d',k))
subplot(1,2,2)
plot(t,y(:,k+1))
legend(sprintf('leg%d',k+1))
title(gca,sprintf('title%d',k+1))
xlabel(gca,sprintf('x%d',k+1))
ylabel(gca,sprintf('y%d',k+1))
end
%------------------------The code---------------------------------
fig=findobj('type','figure')
n=numel(fig);
for m=2:-1:1
figure
for k=n:-1:1
fig1=fig(k);
ii=get(fig1,'children')
aa=findobj(ii,'type','axes')
gg=findobj(ii,'type','legend')
o=aa(m)
p=gg(m)
x=get(get(o,'Xlabel'),'String')
y=get(get(o,'Ylabel'),'String')
titre=get(get(o,'title'),'String')
legende=get(p,'String')
subplot(n,1,k)
copy(allchild(o),gca)
xlabel(x)
ylabel(y)
title(titre)
legend(legende)
end
end
  댓글 수: 4
Deniz Baturay
Deniz Baturay 2016년 3월 25일
It gives error.Attempted to access gg(2); index out of bounds because numel(gg)=0.
Deniz Baturay
Deniz Baturay 2016년 3월 25일
I changed 'type' as 'tag' for legend line. In one figure, legends seems into figure, but other things go wrong. In other figure, left sides graphs doesn't seem. Only legends seem :(

댓글을 달려면 로그인하십시오.


Jos (10584)
Jos (10584) 2016년 3월 24일
Take a look at copyobj
figure(1)
subplot(1,2,1) ; ph{1} = plot(cumsum(rand(10,20)),'bo') ;
figure(2)
ax = subplot(3,4,3) ; copyobj(ph{1}, ax)
  댓글 수: 1
Deniz Baturay
Deniz Baturay 2016년 3월 24일
Thanks for the answer, but I have legends in the figures.

댓글을 달려면 로그인하십시오.


KSSV
KSSV 2016년 3월 24일
Try the following code with attached .fig file:
clc; clear all
% Extract data from figure
open('Junk.fig') ;
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects in axes
for i = 1:length(axesObjs)
xdata{i} = get(dataObjs{i}, 'XData'); %data from low-level grahics objects
ydata{i} = get(dataObjs{i}, 'YData');
end
clf ;
plot(xdata{2},ydata{2},'r') ;
hold on
plot(xdata{1},ydata{1},'b') ;
You need to run a loop for each .fig.
  댓글 수: 4
Deniz Baturay
Deniz Baturay 2016년 3월 26일
Dr. Siva Srinivas Kolukula Graphs have legends, xlabel and y label. I think your code didn't work because of this.
Deniz Baturay
Deniz Baturay 2016년 3월 26일
I checked your code with your figure. This is not my question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by