I am looking for a way to merge two Matlab plots. I have the figure files for each of them as fig1.fig and fig2.fig One figure contains a plot which runs for a certain range e.g 1 to 100 and the other figure contains the continuation of the first plot e.g 101 to 200. Each of these plots takes around 8 hours, so I do not want to replot them. Is there any simple way of merging these two plots?
1
votes
1 Answers
7
votes
It sounds like you want to join up your data, so you need to extract the x and y data from each of your plots. If you have a line plot, you can load the first .fig file
e.g.
and then type
a = gca
handles = findobj(a)
isLine = strcmp(get(handles, 'Type'), 'line')
XData1 = get(handles(isLine), 'XData')
YData1 = get(handles(isLine), 'YData')
That will extract the x and y data for your line, from your first plot.
Now close all your figures and load your second plot:
a = gca
handles = findobj(a)
isLine = strcmp(get(handles, 'Type'), 'line')
XData2 = get(handles(isLine), 'XData')
YData2 = get(handles(isLine), 'YData')
You can now plot your merged plot with:
figure
plot([XData1 XData2], [YData1 YData2])
title('mergedPlot')