为什么将对象分配给子图声明对象被删除?
Why does assigning an object to a subplot claim object is deleted?
我想在不同的位置制作 4 个独立的子图。我的目标是首先设置图形,然后向每个图形添加对象,目的是稍后为对象设置动画。在我尝试将对象作为子图的父级之前,一切似乎都运行良好。当我使用以下代码构建子图后立即添加对象时,不会发生错误。
H1 = subplot('Position',[0.2,0.2,0.2,0.2]);
rectangle('Parent',H1,'Position',[10,20,20,20])
当我尝试回调到之后构建的图形时,错误似乎增加了,如我目前正在处理的代码所示。
screencolor = [0,0,0];
StimWindow = figure('MenuBar','none', ... % Build Window for stimulus
'Color',screencolor);
figuresize = get(0,'ScreenSize');
set(StimWindow,'Position',figuresize);
set(0,'defaultaxesposition',[0 0 1 1])
Stimsubfigures{1} = subplot('Position',[0,0,1,1]); % First subplot figure which spans the entire screen
set(Stimsubfigures{1},'xLim',[0,100])
set(Stimsubfigures{1},'YLim',[0,100])
set(Stimsubfigures{1},'Visible','off')
% create subplots for stim system 3 plate setup
for aa = 2:4
Stimsubfigures{aa} = subplot(...
'Position',[.01+aa*.21,.2,.2,.2], ...
'color','none');
set(Stimsubfigures{aa},'xLim',[0,100])
set(Stimsubfigures{aa},'YLim',[0,100])
set(Stimsubfigures{aa},'Visible','off')
end
OrtDish = rectangle(...
'Parent',Stimsubfigures{1},...
'Position', [0,0,100,100],...
'facecolor',screencolor,...
'edgecolor',[.5,0,0],...
'curvature',[1,1],...
'LineWidth',3);
显示的错误表明无法将对象附加到已删除的句柄。当我到达计算机时,我会提供确切的错误。
这很奇怪,因为句柄没有被删除,它存储在一个单元格矩阵中。
问题来自于重叠subplot
:你画了一个完整的子图,然后在它上面画了一些新的。
正如 Matlab 文档所说,
If a SUBPLOT specification causes a new axes to overlap an existing axes, the existing axes is deleted - unless the position of the new and existing axes are identical.
如果将 subplot
替换为 axes
,就可以了。
我想在不同的位置制作 4 个独立的子图。我的目标是首先设置图形,然后向每个图形添加对象,目的是稍后为对象设置动画。在我尝试将对象作为子图的父级之前,一切似乎都运行良好。当我使用以下代码构建子图后立即添加对象时,不会发生错误。
H1 = subplot('Position',[0.2,0.2,0.2,0.2]);
rectangle('Parent',H1,'Position',[10,20,20,20])
当我尝试回调到之后构建的图形时,错误似乎增加了,如我目前正在处理的代码所示。
screencolor = [0,0,0];
StimWindow = figure('MenuBar','none', ... % Build Window for stimulus
'Color',screencolor);
figuresize = get(0,'ScreenSize');
set(StimWindow,'Position',figuresize);
set(0,'defaultaxesposition',[0 0 1 1])
Stimsubfigures{1} = subplot('Position',[0,0,1,1]); % First subplot figure which spans the entire screen
set(Stimsubfigures{1},'xLim',[0,100])
set(Stimsubfigures{1},'YLim',[0,100])
set(Stimsubfigures{1},'Visible','off')
% create subplots for stim system 3 plate setup
for aa = 2:4
Stimsubfigures{aa} = subplot(...
'Position',[.01+aa*.21,.2,.2,.2], ...
'color','none');
set(Stimsubfigures{aa},'xLim',[0,100])
set(Stimsubfigures{aa},'YLim',[0,100])
set(Stimsubfigures{aa},'Visible','off')
end
OrtDish = rectangle(...
'Parent',Stimsubfigures{1},...
'Position', [0,0,100,100],...
'facecolor',screencolor,...
'edgecolor',[.5,0,0],...
'curvature',[1,1],...
'LineWidth',3);
显示的错误表明无法将对象附加到已删除的句柄。当我到达计算机时,我会提供确切的错误。
这很奇怪,因为句柄没有被删除,它存储在一个单元格矩阵中。
问题来自于重叠subplot
:你画了一个完整的子图,然后在它上面画了一些新的。
正如 Matlab 文档所说,
If a SUBPLOT specification causes a new axes to overlap an existing axes, the existing axes is deleted - unless the position of the new and existing axes are identical.
如果将 subplot
替换为 axes
,就可以了。