The implementation presented in the Undocumented MATLAB blog post does still work in versions past R2014b.
This code, for example:
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
Outputs the XYZ coordinates of your brushed data points to the command window. Tested in R2014b and R2015a.
This is the exact same implementation as the one in the linked blog post. The undocumented BrushHandles
property is a property of MATLAB's line object, which is a child of the axes you plotted it in. The eventdata
variable passed to all callbacks provides the axes being brushed, so the eventdata.Axes.Children
portion is equivalent to the hLine
portion of the blog post.
You received the error because you were attempting to access the undocumented property for all of the lines at once. To work around this you iterate through the children of the invoking axes object, which are all of your lines.