Look and extract numbers within a range in MATLAB

1 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-3-19
编辑:Azzi Abdelmalek 2013-3-19
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),:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by