How to combine group of plots into one with separate marker

조회 수: 1 (최근 30일)
mohammed
mohammed 2022년 10월 7일
답변: J. Alex Lee 2022년 10월 9일
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
Benjamin Thompson
Benjamin Thompson 2022년 10월 7일
Do you have the source data and scripts used to create the figure files? If you can plot a new figure using data set 1, then use the "hold on" command, and call plot again with data set 2. Call "hold off" when all data is added to one figure.
The plot function accepts a third parameter which specifies line type and marker, per this snippet from the documentation:
Various line types, plot symbols and colors may be obtained with
PLOT(X,Y,S) where S is a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus
at each data point; PLOT(X,Y,'bd') plots blue diamond at each data
point but does not draw any line.
mohammed
mohammed 2022년 10월 8일
i don't have the source data thats why i used this method

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

답변 (1개)

J. Alex Lee
J. Alex Lee 2022년 10월 9일
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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by