필터 지우기
필터 지우기

How to compare in matlab

조회 수: 3 (최근 30일)
Sukumar Palo
Sukumar Palo 2011년 2월 10일
Hi,
I have an array with 2*100 size. i want to check that a variable k with the 1st row of the array that k is equal or not to any value in the 1st row.
A=[3 4 6 3 5 4 2 56 7 7; 56 34 2 4 6 7 7 78];
variable k=3;
so i want to check k with A(1,1);A(1,2);A(1,3);......;A(1,n)

답변 (5개)

Vieniava
Vieniava 2011년 2월 10일
Try this:
TestA=( A(1,:) == k);
TestA is a logic vector or this
TestVec=find( A(1,:) == k);
TestVec - is a vector containg positions of matched values
  댓글 수: 2
Sukumar Palo
Sukumar Palo 2011년 2월 10일
my array is of 201111111*2
in that how to find whether a 1 is returned or not in TestA.
Vieniava
Vieniava 2011년 2월 10일
use TestVec - TestVec would consist of indices of matched values ( A(1, TestVec) = k ).

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


Sukumar Palo
Sukumar Palo 2011년 2월 10일
my array is of 2*201111111 in that how to find whether a 1 is returned or not in TestA.
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 2월 10일
not clear at all...

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


Walter Roberson
Walter Roberson 2011년 2월 13일
ismember(k, TestA(1,:))

Andreas Goser
Andreas Goser 2011년 2월 10일
I suggest comparing the difference of A in k with a very small number:
f=abs(k-A(1,:))<2*eps
This avoids a couple of numerical surprises...
  댓글 수: 1
Jan
Jan 2011년 2월 13일
What about "2 * eps(k)" to consider k'th magnitude?

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


Bo
Bo 2011년 2월 13일
Any(A(1,:)==k)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by