Look and extract numbers within a range in MATLAB

1 view (last 30 days)
Hi, i am still learning about matlab, so here is my question. I got two matrix dimension mx3 and nx3.
A=[2,2345,111; 2,2344,3000; 4, 2345,200 ; 4,2000,200; 2,2346,22; 4,2111,1; 4,3111,1]
B=[2,2345,112; 2,2344,3110; 4, 2345,192 ; 4,2000,184; 2,2346,22; 4,2111,456]
Lets say we are looking for 3rd column. A(:,3) are condition for B(:,3).What i want to do is to extract all rows that value from A column 3 is in range of value from B+-10%
Example:
Lets take first row from A: 2,2345,111 and B: 2,2345,112. Value 112 is within a range 10% deviation of 111, so we extract those rows in a new matrix. If we take second row we see that 3110 is bigger than 3000+-10%, so we dont extract that in new matrix.
I hope you understood my question. Thank you very much in advance.
Nice day, Nejc

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 19 Mar 2013
Edited: Azzi Abdelmalek on 19 Mar 2013
A=[2,2345,111;2,2344,3000;4,2345,200;4,2000,200; 2,2346,22; 4,2111,1; 4,3111,1]
B=[2,2345,112;2,2344,3110;4,2345,192;4,2000,184;2,2346,22;4,2111,456;4,3110,1]
C=A(abs(A(:,3)-B(:,3))<=abs(B(:,3)*.1),:)

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!