我想在一些次要情节中绘制一些传记。请帮我完成这个任务。 有我的代码:
cm = [0 1 1 0 0;1 0 0 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 0 0];
cm2 = [0 1 1 0 1;1 0 1 1 1;1 0 0 0 0;0 0 0 0 1;1 0 1 1 0];
figure(18);
subplot(2,1,1);
view(biograph(cm));
subplot(2,1,2);
view(biograph(cm2));
答案 0 :(得分:2)
<强>代码:强>
h(1) = figure;
view(biograph(cm));
fig(1)=gcf; ax1=gca; % Figure and axes handles
c1 = get(fig(1), 'Children');
copyobj(c1,h(1)); % Copying the object to h(1)
h(2) = figure;
view(biograph(cm2));
fig(2)=gcf; ax2=gca; % Figure and axes handles
c2 = get(fig(2), 'Children');
copyobj(c2,h(2)); % Copying the object to h(2)
figure;
% Creating and getting handles of subplot axes
% Retrieving properties of children and copying to new parents and hiding the axes lines
s1 = subplot(1,2,1); bg1 = get(ax1,'children'); copyobj(bg1,s1); axis off;
s2 = subplot(1,2,2); bg2 = get(ax2,'children'); copyobj(bg2,s2); axis off;
close(fig); close(h); % Closing previously opened figures
<强>输出:强>
答案 1 :(得分:2)
这里是@ SardarUsama's answer的修改,应该适用于较新的MATLAB版本(其中gcf
不再返回传记图的句柄):
function hF = q41124642()
cm = [0 1 1 0 0; 1 0 0 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 0 0];
cm2 = [0 1 1 0 1; 1 0 1 1 1; 1 0 0 0 0; 0 0 0 0 1; 1 0 1 1 0];
% Look for biograph figures before and after ploting to know which figures to use
hBG{1} = findall( 0, 'Tag', 'BioGraphTool' ); % Before
view( biograph(cm) );
view( biograph(cm2) );
hBG{2} = findall( 0, 'Tag', 'BioGraphTool' ); % After
hBG = setdiff( hBG{2}, hBG{1} ); % (The difference contains the new figures)
% Create a new figure to hold the subplots:
hF = figure();
% Create and get handles of subplot axes:
s(1) = subplot(1,2,1);
s(2) = subplot(1,2,2);
% Retrieve children and copy to new parents, hiding the axes
IS_CHILD_AX = arrayfun( @(x)isa( x, 'matlab.graphics.axis.Axes' ), hBG(1).Children );
copyobj( hBG(1).Children(IS_CHILD_AX).Children, s(1) );
copyobj( hBG(2).Children(IS_CHILD_AX).Children, s(2) );
axis( s, 'off' );
% Close the biograph figures:
close(hBG);
注意:
'Tag','BioGraphTool'
跟biograph.view
进入biograph.bggui
,直到找到创建的数字的某些识别功能。如果没有这个,我们只需要findall
询问一个数字列表,两次,应用相同的差异逻辑。