Matching pair to some reference value

Dear All
I need help to find out the pairs which are equal to the some reference value e.g my data is given as
A(i)=d2_f(i);
B=([e1(i);e2(i);e3(i);e4(i);e5(i);e6(i);e7(i);e8(i);e9(i);e10(i);e11(i)]);
i want to find out which pairs in B can meet the value of A
Thanks in advance for answering

답변 (2개)

KSSV
KSSV 2019년 4월 9일
편집: KSSV 2019년 4월 9일

0 개 추천

tol = 10^-6 ;
idx = abs(B-A)<=tol ;
[A B(idx')]

댓글 수: 6

Amin Waqas
Amin Waqas 2019년 4월 9일
how i can use this under loop
for i=1:1:17520
as value of A and B are changing from one i- index to other i-index
KSSV
KSSV 2019년 4월 9일
Is A always a single number?
Amin Waqas
Amin Waqas 2019년 4월 9일
yes
tol = 10^-6 ;
iwant = cell(17520,1) ;
for i = 1:17520
A=d2_f(i);
B=([e1(i);e2(i);e3(i);e4(i);e5(i);e6(i);e7(i);e8(i);e9(i);e10(i);e11(i)]);
idx = abs(B-A)<=tol ;
iwant{i} = [A B(idx')] ;
end
You may read about ismembertol and avoid loop. Read about it.
Amin Waqas
Amin Waqas 2019년 4월 9일
Following error is reported while running this segment
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in asdsad (line 96)
iwant{i} = [A B(idx')]
The error is simple.......see A is a single number and if B is row matrix..no error...if it is column matrix there will be error. Remove the transpose in idx.
iwant{i} = [A B(idx)]
madhan ravi
madhan ravi 2019년 4월 9일

0 개 추천

Simply use ismembertol()

이 질문은 마감되었습니다.

질문:

2019년 4월 9일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by