I am having a (mathematica 8.0.1.0-) problem which I cannot solve by myself. I have measurement data in a matrix, I want to select some of them and then add them up.
To explain my problem better, here an easy example. The data can be produced by a matrix S:
S = Table[ -Sin[i/2] - Sin[j/2], {i,20}, {j,20}];
They can be nicely plotted with:
xmin = N[Min[S]];
xmax = N[Max[S]];
mycolorfun = Function[ Blend[{Blue,Cyan,Green,Yellow,Red},#] ];
and
MatrixPlot[S, PlotRange -> {All,All,All}, AspectRatio -> 1/1,
ColorFunction -> (mycolorfun[ Rescale[ #1{xmin,xmax} ] ]&),
ColorFunctionScaling -> False, MaxPlotPoints -> Automatic,
FrameLabel -> {y,x} ]
Then one should get a picture similar to this one:
Now I want to select the data which are inside of the brown drawn polygon. These data should be added up at the end.
How can I do this?
Ok, I could use rectangles and build a sub-matrix by choosing/guessing good start and end indices. Then I just have to build the sum of this sub-matrix. But I would prefer polygons (more precise if we do not argue about little problems with the matrix values which are crossed by the line of the polygon). And I would love it if I could select my region of interest (ROI) directly by “painting” the polygon into the Matrix (no more time consuming choosing/guessing of matrix indices).
Could somebody here help me with my problem? If it is not solvable with mathematica, is there some other program which I could use?
I would be very happy about some help and hints!