# Calculation of the mean of array data points lying under a predefined rectangle

I have data points in an array, and a predefined rectangle lying within the area of my array. My goal is to calculate the Mean of my array points lying under the area of the rectangle. But I have one problem, the coordinates of the rectangle in my array are determined from the bottom left corner, BUT the coordinates in my table function are determined from the upper left corner. Which means that I will always take different values than the rectangle are overlapping. Has someone an idea how to fix this?

TestDataPoints = RandomInteger[10, {6, 6}]
TestDataPointsGraph =
ArrayPlot[TestDataPoints ,
PlotRange -> All,
ColorFunction -> ColorData["SunsetColors"],
ImageSize -> Small,
Frame -> False]

TestQuader = Rectangle[{1, 1}, {3, 3}]

Table[
TestDataPoints[[RowData]][[ColumnData]],
{RowData, 3, 1}, {ColumnData, 1, 3}]


I am not sure I understand what you asking. Especially, I do not understand why you introducing image processing into you work. Just to find the mean of a subarray requires no resort images and image processing. So I suggest the following. If it doesn't work for you, I ask you to explain -- by updating your question, not by commenting on this answer -- why this isn't what you want.

SeedRandom[42]; pts = RandomInteger[10, {6, 6}];
pts // MatrixForm


rect = pts[[4 ;; 6]][[All, 1 ;; 3]];
rect // MatrixForm


N[Mean[Flatten[rect]]]


5.77778

• Thank you a lot, that is an easier way! I guess for you the next questions is an easy task, but how can I now mark the rect data e.g. with a frame in my arrayplot? – Jacccy Mar 31 '16 at 13:59
• Why not use pts[[4 ;; 6, 1 ;; 3]]? – BlacKow Mar 31 '16 at 17:55