在
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对象的子对象,这是您的所有行。