这个问题需要用数组和索引来思考。
首先,您需要确定您感兴趣的区域。如果您没有子区域的坐标,可以使用例如, IMRECT
%# create a figure and display your 2D array (B)
figure,imshow(B,[])
regionCoords = wait(imrect);
%# round the values to avoid fractional pixels
regionCoords = round(regionCoords);
regionCoords
与[yMin,xMin,width,height]
,其中xMin
和yMin
分别左上角的行和列索引,阵列。
现在你可以提取子阵列和发现的最大
xMin = regionCoords(2);
yMin = regionCoords(1);
xMax = regionCoords(2) + regionCoords(4) - 1;
yMax = regionCoords(1) + regionCoords(3) - 1;
subArray = B(xMin:xMax,yMin:yMax);
%# transform subArray to vector so that we get maximum of everything
[maxVal,maxIdx] = max(subArray(:));
所有剩下的就是要回行和列的坐标(使用ind2sub
),并把它们转化,这样的位置和价值,他们对应于原始数组的坐标([1 1]
的subArray
是原始数组的坐标中的[xMin,yMin]
)。
%# for the size of the subArray: use elements 4 and 3 of regionCoords
%# take element 1 of maxIdx in case there are multiple maxima
[xOfMaxSubArray,yOfMaxSubArray] = ind2sub(regionCoords([4 3]),maxIdx(1));
xOfMax = xOfMaxSubArray + xMin - 1;
yOfMax = yOfMaxSubArray + yMin - 1;
要检查一切正常,你可以用B(xOfMax,yOfMax)
比较maxVal
。
-1:请显示您迄今为止尝试过的方法 - 有什么用?什么没有?在你推动我们之前,让* SOME *尝试你的作业!对于所有的“MATLAB常客”:我将不胜感激您在以下元讨论中的输入:http://meta.stackexchange.com/q/108521/168373 –
考虑在进行快速搜索之前,您会问一个将会浪费人们的问题时间和杂乱的网站。 –