Search code examples
matlabindexingcomplex-numbers

Get the position of complex vector in complex matrix


I need to get the position of vector (which is complex) in a complex matrix.

For example I have the matrix X as below:

X = [ -0.7071 + 0.7071, 0.00 + 0.00i, 0.00 + 0.00i, 0.00 + 0.00i;
       0.00 + 0.00i, -0.7071 + -0.7071, 0.00 + 0.00i, 0.00 + 0.00i;
       0.00 + 0.00i, 0.00 + 0.00i, -0.7071 + 0.7071, 0.00 + 0.00i; 
      -0.7071 + 0.7071, -0.7071 + 0.7071, 0.00 + 0.00i, 0.00 + 0.00i; 
      -0.7071 + 0.7071, 0.00 + 0.00i, -0.7071 + 0.7071; 0.00 + 0.00i ];

And I have a complex vector

Y = [ 0.00 + 0.00i, 0.00 + 0.00i, -0.7071 + 0.7071, 0.00 + 0.00i ]; 

So, what I need is that to get the index of Y in the matrix X. In my example, it's 3.


Solution

  • The ismember function can be used to determine wheter a vector is a row in a matrix:

    [~,indx] = ismember(X', Y', 'row')
    

    indx will be a vector which says if Y' is in that row of X' (columns when talking about Y and X). To know the index you want, you just have to do:

    solution = find(indx == 1)
    

    That will return all the columns that Y appears X.