Compare two array values that meet criteria

조회 수: 1 (최근 30일)
ALDO
ALDO 2020년 9월 10일
댓글: Adam Danz 2020년 9월 10일
Hi
I have two arrays. I know that location of each array value.
the locations are as follows
location Array A= 1253 1982 50616 50665 61911 61999 62560 68112 68162 68376 73573 94747 99547 104436 104680 107002 .... (213 elements)
location Array B=1240 1953 4498 47993 51165 52541 52709 53983 54187 59203 59618 59829 61134 62035 64844 72766 72887 ....(130 elements)
what i would like to know is location value in A matchs B +-15
for example take the first value in A (1253) compare it to all the values in B if you find a value in B that is within the range (1253-15):(1253+15) take both location values and put it in an array (n,2). colum 1 value of A, column 2 value of B.
Thanks you for your help!

채택된 답변

Adam Danz
Adam Danz 2020년 9월 10일
편집: Adam Danz 2020년 9월 10일
Your example only contains 1 close-match of values between A and B that are +/- 15 units apart.
% Raw data; A and B can be any length and do not have equal matches.
A = [ 1253 1982 50616 50665 61911 61999 62560 68112 68162 68376 73573 94747 99547 104436 104680 107002];
B = [1240 1953 4498 47993 51165 52541 52709 53983 54187 59203 59618 59829 61134 62035 64844 72766 72887];
% Distance matrix
% d(i,j) is the distance between A(i) and B(j)
d = abs(A(:) - B(:).');
% Find close-matches
[Aidx, Bidx] = find(d<=15);
% Produce outputs
% z is nx2 containing the n close-match values from A and B
% zIdx is nx2 containing the indices of A and B that were matched
% so, [A(zIdx(i,1)), B(zIdx(i,2))] == z(i,:)
z = [A(Aidx); B(Bidx)]';
zIdx = [Aidx, Bidx];
  댓글 수: 2
ALDO
ALDO 2020년 9월 10일
Thank you so much for you Fast responce! It worked perfectly!
Adam Danz
Adam Danz 2020년 9월 10일
Glad I could help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Antennas, Microphones, and Sonar Transducers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by