为了计算二维矩阵Y的局部最大值,我使用以下方法
[~, indices]= localmax(Y); 但indices是一维的。如何将其转换回2D,以便在Y中访问其对应的元素?
发布于 2015-10-14 13:21:16
来自localmax
lmaxima非零值的线性指数。使用ind2sub将线性索引转换为矩阵、行和列索引。
例如:
inputmatrix = ...
[3 2 5 3
4 6 3 2
4 4 7 4
4 6 2 2];
[~,indices] = localmax(inputmatrix,4,false);
[I, J] = ind2sub(size(indices), indices);编辑:我也应该澄清的。正如@LuisMendo在上面的注释中提到的那样,您可以通过使用Y直接使用线性指数访问Y(indices)的元素。
https://stackoverflow.com/questions/33126338
复制相似问题