Filter löschen
Filter löschen

how to find the equality of 2 numbers?

1 Ansicht (letzte 30 Tage)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran am 10 Sep. 2012
a e
1 1
1 2
3 2
3 2
The above is my input table. Check 'a' for the value '1'. The corresponding 'e' value differs. So, we should not consider it. Check 'a' the value of '3'. The corresponding 'e' values are same. How to develop code for this?
  5 Kommentare
Image Analyst
Image Analyst am 10 Sep. 2012
Then see my answer. Also, what does "class(a)" show when you issue that command? If you want to make absolutely sure a and e are integers, wrap them in an int32() when you create them.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 10 Sep. 2012
AE = [a e]; %The initial array
out = AE(abs(diff(AE,1,2)) < eps(100),:);
  1 Kommentar
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran am 10 Sep. 2012
Hi Andrei,Thanks. Your answer matches my requirement 90%.. for no.'2' your code works fine. Since there is a deviation in '1' it should not come. You can see the change in the value of 'e' when the value of 'a' is 1. Can you modify the code

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Adrian Dronca
Adrian Dronca am 10 Sep. 2012
I think you should consider using isequal() . The function works with single, double, string.

Image Analyst
Image Analyst am 10 Sep. 2012
If they're integers, use ==, like
if a == e
if they're floating point, you need to check against a tolerance:
if abs(a-e) < 0.0001

Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran am 12 Sep. 2012
When you go through the first two rows, you can find that the change in the values. So, '1' should be omitted. There is no change in 3rd and 4th row.. 'e' value does not gets changed. So, we can consider 'e' .
How to do this??

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by