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!