How to combine group of plots into one with separate marker

1 view (last 30 days)
i use this code to cobine tow figures but i want help to make loop to combine more than tow figures
thnx
fh1 = open('f1.fig');
fh2 = open('f2.fig');
ax1 = get(fh1, 'Children');
ax2 = get(fh2, 'Children');
ax2p = get(ax2(1),'Children');
copyobj(ax2p, ax1(1));
  2 Comments
mohammed
mohammed on 8 Oct 2022
i don't have the source data thats why i used this method

Sign in to comment.

Answers (1)

J. Alex Lee
J. Alex Lee on 9 Oct 2022
Assuming that each figure only has 1 axes and you want the first axes to be the one you want to copy into
fig(1) = open('f1.fig');
fig(2) = open('f2.fig');
fig(3) = open('f3.fig');
% ...
ax = findobj(fig(1),"Type","Axes");
% identify the axes of the first figure
for i = 2:numel(fig)
PlotObjs = findobj(fig(i),"Type","Line","-or","Type","Scatter")
copyobj(PlotObjs,ax)
end
If you want to re-do the markers, identify all the plot objects and re-set their linespec/colors.
PlotObjs = findobj(fig(1),"Type","Line","-or","Type","Scatter")
for i = 1:numel(PlotObjs)
set(PlotObjs(i),"LineStyle",...)
set(PlotObjs(i),"Marker",...)
set(PlotObjs(i),"Color",...)
% etc
end
You can pre-generate the combinations of linestyle, markers, etc ahead of time and save into arrays to index in the loop

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!