-2

I am writing a GUI in GUIDE and need to read brushed data from any of 3 axes. I kept recieving a callback error. Initially, I thought I was failing due to my inexperience. However, following further research, there are some suggestions that the latest MATLAB update resulted in people not being able to access brushed data at all.

My issues are very similar to this thread here: http://www.mathworks.com/matlabcentral/answers/223441-problem-with-brush-matlab-r2015a. Anyone have any answers?

DeeWBee
  • 695
  • 4
  • 13
  • 38
  • @excaza my previous question was out-of-date. That method isn't even used anymore in versions past R2014b. – DeeWBee Aug 12 '15 at 16:43
  • My point still stands, this question is missing useful information that was present in the other question. There is no explanation of the GUI you're utilizing (you have more than one axis, important point), what you're trying to do, what you have tried, the error messages recieved, etc. Regardless, the older implementation *does* work in versions past R2014b. – sco1 Aug 12 '15 at 16:47

1 Answers1

1

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.

sco1
  • 12,154
  • 5
  • 26
  • 48
  • Okay, first: thank you. Second: this method sort-of works for me... It's hard to explain. But in essence, one of my axes displays multiple plot lines (6 to be exact). I still get the error when I brush that axes. Also, where did you find this? I poured over the Undocumented MATLAB post and couldn't quite figure it out. – DeeWBee Aug 12 '15 at 16:58
  • 1
    I have updated my answer. Again, information that would be useful to include in your initial question... – sco1 Aug 12 '15 at 17:06
  • 1
    I've also added some explanation, hopefully it's sufficient. – sco1 Aug 12 '15 at 17:10
  • Yeah super helpful. What threw me for a loop is on the MathWorks website regarding Brush, they discuss ActionPostCallback. However, their implementation seemed to imply that eventdata and event_data are different. Also that I had to include both src and eventdata in the callback arguments. – DeeWBee Aug 12 '15 at 17:13