comparing two matrices of different dimensions
Afficher commentaires plus anciens
i have two matrices,A with dimension (23,2) and B with dimension (50465,2) .
i compare the first col of each matrix.
i need to keep values such that : abs(A(:,1)-B(:,1)) < 0.5.
C has four col : A(:,1) B(:,1) A(:,2) B(:,2)
my trial :
num_rows1=size(A(:,1));
num_rows2=size(B(:,1));
for i=1:1:num_rows1
for j=1:1:num_rows2
if abs(A(j,1)-B(i,1))<=0.5
%if data1(i,1)==0
% data1(i,1)=[];
% end
c1(j,[1:4])=[A(i,1),B(j,1), A(j,2), B(i,2)] ;
end
end
end
++++
ANY HELP
2 commentaires
Bruno Luong
le 20 Août 2023
"ANY HELP"
Why? for what?
Bruno Luong
le 20 Août 2023
c1(j,[1:4])=[A(i,1),B(j,1), A(j,2), B(i,2)] ;
You take an element from row #j (and 2nd column) of A (third element of rhs) and j supposes to be up to 50465?
What did you said? A has 23 rows?
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 20 Août 2023
% Create simple, sample integer data.
A = randi(9, 15, 2) % [x, y]
B = randi(9, 25, 2)
% Find distances between each each point and every other point.
distances = pdist2(A, B)
% Find map of where distances are less than some threshold
threshold = 3; % Whatever closeness value you want.
closeDistances = distances <= threshold
[rowsOfA, rowOfB] = find(closeDistances)
% Get in form of xA, xB, yA, yB
C = [A(rowsOfA, 1), B(rowOfB, 1), A(rowsOfA, 2), B(rowOfB, 2)]
2 commentaires
ahmad Saad
le 20 Août 2023
Image Analyst
le 21 Août 2023
Then we're not sure what you're asking when you tersely say "Any help". You have a for loop, which seems to be your "preferable" way. So what's the problem?
Catégories
En savoir plus sur Pattern Recognition dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!