[英]Find one non-diagonal minimum element from a matrix
Is there a shortest way to find the minimum of non-diagonal elements of the matrix along with its index in matlab. 有没有最短的方法来找到矩阵的非对角线元素及其在Matlab中的索引的最小值。
If A= [1 2 3; 如果A = [1 2 3; 4 1 3;
4 1 3; 4 4 4];
4 4 4]; then i want to return the index of the minimum non-diagonal element.
那么我想返回最小非对角元素的索引。 Here that will be 2 in the first row and second column.
在第一行和第二列中将为2。 So, I want to return (1,2).
因此,我想返回(1,2)。 Thanks.
谢谢。
For a fully vectorized alternative try 对于完全矢量化的替代方法,请尝试
B = (A + diag(Inf(size(diag(A))))); % put Inf on diagonal
[~,ndx] = min(B(:)); % get the linear index of the minimum value
[r,c] = ind2sub(size(A),ndx); % get row, column of corresponding to linear index
for k=1:size(A,1)
A(k,k) = inf;
end
[row,col] = find(A==min(A(:)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.