필터 지우기
필터 지우기

How to plot multiple figures (.fig) into one figure?

조회 수: 43 (최근 30일)
Saad Khan
Saad Khan 2017년 4월 5일
댓글: AMIT MALGOL 2019년 5월 3일
Dear Community member, Im new to MATLAB and in need of your assistant. I have different plots which i saved as figures using saveas function and .fig format. Is it possible to somehow take the figures from each folder and then make one plot? the setup of the figures(standard 2d x-y plot) are exactly the same but each figure contains "circle" points and a curve which is based on a model. but with different values ofcourse. I want to show the differences of these "curve" fits. I have for example: model1.fig model2.fig
one friend suggested "hold on" but im not sure how to since im really really new to MATLAB. your help will be much appreciated. Thank you in advance Best Regards Saad Khan
  댓글 수: 1
AMIT MALGOL
AMIT MALGOL 2019년 5월 3일
f=openfig('model1.fig');
H=findobj(f,'Type','line');
x_data=get(H,'xdata');
y_data=get(H,'ydata');
g=openfig('model2.fig');
G=findobj(g,'Type','line');
x1_data=get(G,'xdata');
y1_data=get(G,'ydata');
figure(1)
xlabel('x');
ylabel('y');
plot(x_data,y_data);
hold on
plot(x1_data,y1_data);

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2017년 4월 6일
Saad - you could try opening the figure and then grab the handles for the graphics object (or objects) that were drawn on the axes (of that figure). For example, suppose we do
x = -2*pi:0.01:2*pi;
y = sin(x);
h = plot(x,y);
saveas(h,'mySinePlot.fig');
So we have drawn the familiar sine curve and then saved the figure to a file. Now, we open the figure as
close all; % ensure existing figures are closed
open mySinePlot.fig;
If we assume that there is just one child object (for the figure) and that it is the axes, then we could do
hFigAxes = get(gcf,'Children');
We now grab the children for the axes. Given our very simple example, there will be just one child from which we can get the x and y data that we used when calling plot
hSinePlot = get(hFigAxes,'Children');
xData = get(hSinePlot,'XData');
yData = get(hSinePlot,'YData');
If you do the same for the other figure, then you will be able to obtain both sets of x- and y-data of which you can then plot onto the same figure.
Your plots may not be as simple as the above, but start with this code and see what happens. If your axes has more than one child, then loop through all of the children until you find the one that you are looking for (if a plot, then its type is Line).

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by