How to plot multiple figures (.fig) into one figure?
69 次查看(过去 30 天)
显示 更早的评论
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
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
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).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!