开发者

How to Test if row is in matrix?

开发者 https://www.devze.com 2023-02-20 09:17 出处:网络
I am looking for a way to return the index of where a particular row resides in matrix.I can guarantee e开发者_运维技巧very row to be unique, as well as the row to always exist in the matrix.How can I

I am looking for a way to return the index of where a particular row resides in matrix. I can guarantee e开发者_运维技巧very row to be unique, as well as the row to always exist in the matrix. How can I do this in matlab?

For example, Suppose you have a matrix c:

 c =

   1   2   3
   3   2   1

further, you have a matrix b:

b =

   1   2   3

I would like some function func where I could call

func(b,c)
    1

or even just return:

0
1


Use ISMEMBER. If every row is unique, and all you want is the index, you can get it as follows (replace ~ by dummy if you're using Matlab pre-2009b).

[~,index] = ismember(b,c,'rows')
0

精彩评论

暂无评论...
验证码 换一张
取 消