Compare two array values that meet criteria
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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];
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!