为什么轴在Matlab循环中被删除? [英] Why axes handle deleted in Matlab loop?

查看:245
本文介绍了为什么轴在Matlab循环中被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图模拟真实动态条件的代码

Code which tries to mimic the real dynamic condition

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
日志2 hax2 主要在代码

Logs 1 hax2 in more dynamic condition, Logs 2 hax2 mostly in Code

%% 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'

由于某些原因 c c c c b
$ b

Error if failure in hax2 i.e. handle to deleted axes for some reason

%% 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); 

解决方案的一些暂定提案

Some tentative proposals of solutions


  1. 在每个循环的末尾保存句柄;可能的相关线程在MATLAB中绘制时保存轴手柄

  2. ...

  1. Save the axes handle at the end of each loop; possible related thread Save axes handle when plotting In MATLAB
  2. ...

操作系统:Debian 8.5 64位

Matlab:2016a

硬件:华硕Zenbook UX303UA < br>
Linux内核:4.6的backports

OS: Debian 8.5 64 bit
Matlab: 2016a
Hardware: Asus Zenbook UX303UA
Linux kernel: 4.6 of backports

推荐答案

调用,第一个输入应该是一个指定父对象的参数/值对。如果你传递一个单独的句柄图形输入,它假设输入是轴的句柄

When calling axes, the first input should be a parameter/value pair that specifies the parent. If you pass it a single handle graphics input it assumes that input is a handle to an axes

axes(hFig2)

% Error using axes
% Invalid axes handle

或正如你所写的

hax2 = axes(hFig2);

% Error using axes
% Too many output arguments.

因为您传递无效的句柄对它,它没有正确地将句柄分配给新的 hax2 。您可能已经从脚本的以前的 运行中删除了您所看到的 hax2

Because you are passing an invalid axes handle to it, it doesn't properly assign the handle to a new axes to hax2. It is likely that your deleted hax2 that you're seeing is from a previous run of the script.

相反,您需要使用参数/值对来指定轴的属性

Instead, you'll want to use parameter/value pairs to specify the Parent property of the axes.

hax2 = axes('Parent', hFig2);

此外,我将删除无关调用 figure 每次通过循环,因为您明确指定了每个绘图对象的父对象

Also, I would remove the extraneous call to figure every time through the loop since you explicitly specify the parent object of each plot object

这篇关于为什么轴在Matlab循环中被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆