Why some lements are not found using find in matlab array

3 次查看(过去 30 天)
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