Here are some examples of how you can address this issue:
mat = rand(10); %# A 10-by-10 array of random elements vec = -3:3; %# To make a 7-by-7 subarray subArray = mat(5+vec,4+vec); %# Get subarray centered on element (5,4) vec = -2:2; %# To make a 5-by-5 subarray subArray = mat(3+vec,3+vec); %# Get subarray centered on element (3,3)
Of course, you will need to be wary of conditions where your indexes go beyond the matrix that you are indexing, and then decide how you want to deal with this situation (i.e. return only the part of the subarray that is inside the larger matrix, or overlays larger matrix using PADARRAY to avoid this situation, etc.).
EDIT:
To summarize the above for the point sets that you want to receive as arrays, the solutions given by Jonas should work well. The only drawback is that you will need to access the Image Processing Toolbox . Here's a solution that will work without additional toolbars using a , r and c , as you defined them in the question:
blockSize = 3; %
This will give you an array of N-on-1 subArrays , where N is the number of points you have. If, for example, you want to get the maximum subarray value for point 3, you can do the following:
maxValue = max(subArrays{3}(:)); %
To take the average value of the entire subarray, you either first need to remove NaN (using the ISNAN function) or use the NANMEAN function from the Statistics Toolbox :
mat = subArray{3}(:); %
source share