试图模仿真实动态条件的代码
clear all; close all;
hFig2=figure('Units','inches', 'Name', 'Time');
hax2=axes(hFig2);
movegui(hFig2, 'southeast');
index=1;
while (index < 7);
hFig2=figure(hFig2);
u=0:0.01:1+index;
plot(hax2, u); % Give columns 1xXYZ to Matlab
hold on;
axis(hax2, 'xy');
axis(hax2, [0 (size(u,2)/1 - 0) min(u) max(u)]); % to maximise size
axis(hax2, 'off'); % no ticks
index=index+1;
pause(1);
hold off;
drawnow
end;
在更动态的情况下记录1 hax2
,
在代码
hax2
%% Logs 1 in dynamic condition with failure output
% Failure in more dynamic conditions because axes get deleted for some reason
% hax2
%
% hax2 =
%
% handle to deleted Axes
%
%% Logs 2 mostly in Code condition and correct because
% hax2 =
%
% Axes with properties:
%
% XLim: [0 201]
% YLim: [0 2]
% XScale: 'linear'
% YScale: 'linear'
% GridLineStyle: '-'
% Position: [0.1300 0.1100 0.7750 0.8150]
% Units: 'normalized'
如果由于某种原因hax2
handle to deleted axes
失败,则会出错
%% Failure message
% Show all properties
%
% Warning: MATLAB has disabled some advanced graphics rendering features by switching to software OpenGL. For more information, click
% here.
% Error using plot
% Invalid handle.
%
% Error in test_invalid_handle (line 12)
% plot(hax2, u);
解决方案的一些初步建议
axes
句柄;可能的相关主题Save axes handle when plotting In MATLAB 答案 0 :(得分:2)
调用axes
时,第一个输入应该是指定父项的参数/值对。如果您传递单个句柄图形输入,则假定输入是axes
的句柄
axes(hFig2)
% Error using axes
% Invalid axes handle
或者正如你写的那样
hax2 = axes(hFig2);
% Error using axes
% Too many output arguments.
由于您向其传递了无效的axes
句柄,因此它无法正确地将句柄分配给新的axes
到hax2
。您所看到的已删除的hax2
可能是来自之前运行的脚本。
相反,您希望使用参数/值对来指定Parent
的{{1}}属性。
axes
另外,每次循环都会删除对hax2 = axes('Parent', hFig2);
的无关调用,因为你明确指定了每个绘图对象的父对象