MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Sivakumaran Chandrasekaran
on 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?

Answer by Andrei Bobrov
on 10 Sep 2012

Accepted answer

AE = [a e]; %The initial array out = AE(abs(diff(AE,1,2)) < eps(100),:);

Sivakumaran Chandrasekaran
on 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

Answer by Adrian Dronca
on 10 Sep 2012

I think you should consider using **isequal()** . The function works with single, double, string.

Answer by Image Analyst
on 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

See the FAQ for more info: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Answer by Sivakumaran Chandrasekaran
on 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??

## 5 Comments

## Azzi Abdelmalek

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47743#comment_98491

your data are what? string?,double?

## Image Analyst

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47743#comment_98494

I think a and e are the column headers, so the variables named a and e are integers, but they may be of

classint32, uint8, uint16, or even single or double.## Sivakumaran Chandrasekaran

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47743#comment_98499

Yes. As Image Analyst told, 'a' and 'e' are column headers... There is no '' strings'' in my input values

## Image Analyst

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47743#comment_98500

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.

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47743#comment_98585

Please retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags