z=sin(1:100);

hLine=plot(z)

brush on

pause(5)

brushedIdx = logical(hLine.BrushData); % logical array

brushedXData = hLine.XData(brushedIdx);

brushedYData = hLine.YData(brushedIdx);

I used the following code:

global xdata

global ydata

z=sin(1:100);

plot(z)

brush on

h = brush

axesObjs = h.Children(1) ;

dataObjs = axesObjs.Children(1) ;

xdata = dataObjs.XData ;

ydata = dataObjs.YData ;

zdata = dataObjs.ZData ;

but I get the error:

No appropriate method, property, or field ‘Children’ for class ‘matlab.graphics.interaction.internal.brush’.

Infact while trying it first I used the following, but xdata and ydata stored all the variables plotted already , I dont understand why

global xdata

global ydata

z=sin(1:100);

plot(z)

h = gcf ;

axesObjs = h.Children(1) ;

dataObjs = axesObjs.Children(1) ;

xdata = dataObjs.XData ;

ydata = dataObjs.YData ;