Why some lements are not found using find in matlab array

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 9 Lug 2015
  2 Commenti
Satish Salunkhe
Satish Salunkhe il 9 Lug 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 il 9 Lug 2015
Modificato: Satish Salunkhe il 9 Lug 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by