8

Here's the setup:

I've got a graphical plot of data, and I'm trying to find if it's feasible to try to put a box on the figure that can be moved and changed in width and return some values like percentage of and area under the curve. It looks something like this:

Example

Any suggestions on where to start? My feeling was that it might be doable using a more GUI'd interface versus a standard plot.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian
  • 357
  • 1
  • 3
  • 8

1 Answers1

9

I would start with imrect. It is draggable, and you can add callbacks to it.

(Taken directly from MATLAB help)

figure, imshow('cameraman.tif');
h = imrect(gca, [10 10 100 100]);
addNewPositionCallback(h, @(p) title(mat2str(p, 3)));
fcn = makeConstrainToRectFcn('imrect', get(gca,'XLim'), get(gca, 'YLim'));
setPositionConstraintFcn(h, fcn);

Change the addNewPositionCallback to something that suits your needs. Specifically, get the needed pixels from the image (by using the position), and calculate whatever you like.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104