Question

I have a problem when i am working with plots in Matlab. Following are my issues with Plots:

  • How can one select Regions after plotting data using mouse?
  • After selecting the Regions how to get data from that region?

Any Ideas?

Was it helpful?

Solution

Selecting regions with a mouse is quite easy using the rbbox function.

First you add a ButtonDownFcn to the axes you are drawing rbbox on.

hax = axes( ... , 'ButtonDownFcn', @OnClickAxes);

Then you call rbbox within the callback like this

function OnClickAxes( hax, evt )

point1 = get(hax,'CurrentPoint'); % hax is handle to axes
rbbox;
point2 = get(hax,'CurrentPoint'); % hax is handle to axes

end

Here point1 and point2 will define the two corners of the rectangle drawn by your mouse in data coordinates. Type doc rbbox at matlab prompt for more information

Now to answer your second question for 2-D plots.

This bit of code will extract and return the data within the selected region for all lines within an axes.

https://gist.github.com/3107790

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top