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}]
TestQuaderGraphic = Graphics[{Green, TestQuader}]

HighlightImage[TestDataPointsGraph, TestQuaderGraphic]

AreaDetermination =
    {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




  • $\begingroup$ 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? $\endgroup$ – Jacccy Mar 31 '16 at 13:59
  • $\begingroup$ Why not use pts[[4 ;; 6, 1 ;; 3]]? $\endgroup$ – BlacKow Mar 31 '16 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.