Why some lements are not found using find in matlab array

3 vues (au cours des 30 derniers jours)
Satish Salunkhe
Satish Salunkhe le 9 Juil 2015
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Juil 2015
  2 commentaires
Satish Salunkhe
Satish Salunkhe le 9 Juil 2015
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 le 9 Juil 2015
Modifié(e) : Satish Salunkhe le 9 Juil 2015
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by