获取矩阵排序元素的索引

象牙

我试图根据矩阵的值来获取行和列的种类。例如,如果矩阵是

A = [3 4 7; 9 8 6; 2 1 5]

它应该输出

2 1
2 2
1 3
2 3
3 3 
1 2
1 1
3 1
3 2

我认为这应该很简单,但是我不知道如何处理。

自主性

是的,这确实非常简单。

%sort the vector instead of matrix to get linear indices
[~,ind]=sort(A(:),'descend')  

%convert the linear indices to [row,col] subscripts
[I,J]=ind2sub(size(A),ind)

%display desired answer 
[I J]

要删除两列中具有相同值的行:

A(A(:,1)==A(:,2),:)=[]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章