Why some lements are not found using find in matlab array

조회 수: 3 (최근 30일)
Satish Salunkhe
Satish Salunkhe 2015년 7월 9일
편집: Satish Salunkhe 2015년 7월 9일
I used following code
a=0:0.001:3
ismember(2.8,a)
ans=1
later I changed
a=0:0.001:3
ismember(2.8,a)
ans=0
I then checked the element present at
a(2801)
ans=2.80000
then why ismemeber is not showing the element found in array when it actually exists?

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 9일
  댓글 수: 2
Satish Salunkhe
Satish Salunkhe 2015년 7월 9일
I used following code
a=0:0.001:3 ismember(2.8,a)
ans=1
later I changed
a=0:0.001:10 ismember(2.8,a)
ans=0
I then checked the element present at
a(2801)
ans=2.80000
then why ismemeber is not showing the element found in array when it actually exists?
I want to use following code, a=0:0.001:10 b=trimf(a,[2.8 2.8 2.8]) plot(a,b)
except 2.8 rest x values are having y axis value 0. But I am getting all values zeros. can you please help me to reach the goal?
Satish Salunkhe
Satish Salunkhe 2015년 7월 9일
편집: Satish Salunkhe 2015년 7월 9일
However when you are dealing with floating point numbers, or just want to have close matches (+- 1000 is also possible), the best solution I found is the fairly efficient File Exchange Submission: ismemberf http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf
It gives a very practical example:
[tf, loc]=ismember(0.3, 0:0.1:1) % returns false [tf, loc]=ismemberf(0.3, 0:0.1:1) % returns true
Though the default tolerance should normally be sufficient, it gives you more flexibility
ismemberf(9.99, 0:10:100) % returns false ismemberf(9.99, 0:10:100,'tol',0.05) % returns true
I think I resolved problem somewhat

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by