This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Is there any function can be used like find(A==i) in matlab?

Tags: None
(comma "," separated)
xueer
Registered Member
Posts
5
Karma
0
for instance if there is a vector or a matrix include an element 26, how can I find the position (i,j) of 26 in the vector?
I'm new for Eigen, pls give me some help, thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
There is no equivalent. If you know there is only one, you can do:

Code: Select all
ArrayXXf A;
int i, j;
if( (A==26).maxCoeff(&i,&j) )
{
  ...
}
else  // otherwise there is no element equals to 26.
...
xueer
Registered Member
Posts
5
Karma
0
ggael wrote:There is no equivalent. If you know there is only one, you can do:

Code: Select all
ArrayXXf A;
int i, j;
if( (A==26).maxCoeff(&i,&j) )
{
  ...
}
else  // otherwise there is no element equals to 26.
...


dear ggael, I tried as you told me, but there is a mistake at A==26, it says: no operator "==" matches this operands.
Code: Select all
ArrayXXi A(4,4);
   A<<1,56,4,6,
      45,76,43,22,
      3,42,4,2,
      4,6,7,9;
   int i,j;
   if ((A==3).maxCoeff(&i,&j))
   {
      cout<<"Yes";
   }
   else
   {
      cout<<"No";
   }
   
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Works for me. Maybe you're using an old version.
xueer
Registered Member
Posts
5
Karma
0
I changed my Eigen version to 3.1.3 but it still not work, could you give me some details about yours which works well.

just like:

#include <Eigen/eigen>
#include <iostream>
using namespace std;
using namespace Eigen;

int main()
{
ArrayXXi A(4,4);
A<<1,56,4,6,
45,76,43,22,
3,42,4,2,
4,6,7,9;
int i,j;
if ((A==36).maxCoeff(&i,&j))
{
cout<<"Yes";
}
else
{
cout<<"No";
}
return 0;
}
xueer
Registered Member
Posts
5
Karma
0
I've got it. thanks very much


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]