代码之家  ›  专栏  ›  技术社区  ›  DeeWBee

MATLAB:2015a画笔问题

  •  -2
  • DeeWBee  · 技术社区  · 9 年前

    我正在用GUIDE编写GUI,需要从3个轴中的任何一个读取刷过的数据。我一直收到回调错误。最初,我认为我失败是因为我缺乏经验。然而,在进一步研究之后,有人认为,最新的MATLAB更新导致人们根本无法访问刷过的数据。

    我的问题与以下主题非常相似: http://www.mathworks.com/matlabcentral/answers/223441-problem-with-brush-matlab-r2015a 有人有答案吗?

    1 回复  |  直到 9 年前
        1
  •  1
  •   sco1    9 年前

    Undocumented MATLAB blog post 仍然适用于R2014b之后的版本。

    例如,此代码:

    function testcode()
    h.myfig = figure;
    
    h.myax(1) = axes('Parent', h.myfig, 'Units', 'Normalized', 'Position', [0.1 0.1 0.35 0.35]);
    h.myax(2) = axes('Parent', h.myfig, 'Units', 'Normalized', 'Position', [0.55 0.1 0.35 0.35]);
    h.myax(3) = axes('Parent', h.myfig, 'Units', 'Normalized', 'Position', [0.55 0.55 0.35 0.35]);
    
    plot(h.myax(1), 0:10);
    plot(h.myax(2), 10:20);
    
    hold(h.myax(3), 'on');
    plot(h.myax(3), 20:30);
    plot(h.myax(3), 30:-1:20);
    hold(h.myax(3), 'off');
    
    h.mybrush = brush;
    set(h.mybrush, 'Enable', 'on', 'ActionPostCallback', @displayBrushData); 
    
    function displayBrushData(~, eventdata)
    nlines = length(eventdata.Axes.Children);
    brushdata = cell(nlines, 1);
    for ii = 1:nlines
        brushdata{ii} = eventdata.Axes.Children(ii).BrushHandles.Children(1).VertexData;
        fprintf('Line %i\n', ii)
        fprintf('X: %f Y: %f Z: %f\n', brushdata{ii})
    end
    

    将绘制的数据点的XYZ坐标输出到命令窗口。在R2014b和R2015a中测试。

    这与链接的博客文章中的实现完全相同。无证件的 BrushHandles 属性是MATLAB的线对象的属性,它是绘制它的轴的子对象。这个 eventdata 传递给所有回调的变量提供了被刷的轴,因此 eventdata.Axes.Children 部分相当于 hLine 博客文章的一部分。

    您收到错误,因为您试图同时访问所有行的未记录属性。为了解决这个问题,您需要遍历调用axis对象的子对象,这是您的所有行。