Why some lements are not found using find in matlab array

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Jul. 2015
  2 Kommentare
Satish Salunkhe
Satish Salunkhe am 9 Jul. 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 am 9 Jul. 2015
Bearbeitet: Satish Salunkhe am 9 Jul. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by