How to find the position of a real vector in a matrix?

조회 수: 4 (최근 30일)
Cantor Set
Cantor Set 2020년 3월 6일
편집: dpb 2020년 3월 7일
I do have a very big matrix of real numbers, I need a function that takes a vector as input and returns its position in the matrix.
An example:
A =[
0.7081 0.0797 0.1418 0.5849 0.1305
0.0738 0.4849 0.5060 0.8479 0.5003
0.8723 0.1511 0.6346 0.0683 0.7673
0.2021 0.4461 0.7313 0.7355 0.4157
0.7050 0.8435 0.8158 0.2139 0.8008]
Suppose I want to find the position of
v=[ 0.7081 0.0797 0.1418 0.5849 0.1305]
in A
How can I do it?
I edited the question
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 3월 6일
You cannot. Those values do not exist in the matrix.
You need to give the command
format long g
And then display A again.
Cantor Set
Cantor Set 2020년 3월 6일
Sorry, I edited the question

댓글을 달려면 로그인하십시오.

답변 (2개)

dpb
dpb 2020년 3월 6일
>> find(ismember(A,v,'rows'))
ans =
1
>>
works here, but in general for floating point values
>> find(ismembertol(A,v,2*eps,'byrows',1))
ans =
1
>>
is more robust and will avoid surprises.
  댓글 수: 2
Cantor Set
Cantor Set 2020년 3월 6일
I tried it on a very big matrix of real numbers it returned
ans =
Empty matrix: 0-by-1
dpb
dpb 2020년 3월 7일
>> find(ismembertol(w,c,2*eps,'byrows',1))
ans =
1
>>

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2020년 3월 6일
Dists = pdist2(A, v);
[mindist, rowidx] = min(Dists) ;
if mindist > some_tolerance
error('row not found') ;
end
  댓글 수: 3
dpb
dpb 2020년 3월 7일
편집: dpb 2020년 3월 7일
Shouldn't w/ the given example data...altho suppose it's possible with the real data instead of that rounded off in the pasted text instead of actual data from memory.
>> D=pdist2(w,c);
>> [minD,ixMin]=min(D)
minD =
0
ixMin =
1
>>
With the rounded data from the posting it's identically zero.
Did you look at what was returned at all or just complain...
Walter Roberson
Walter Roberson 2020년 3월 7일
Please attach your w and c in a .mat

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 State-Space Control Design and Estimation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by