Find matching indexes in two different size arrays
34 次查看(过去 30 天)
显示 更早的评论
I have two arrays called A and B. I need to to match these two arrays with some tolerence. So that I can get an array like the out put that is given below.(Or any other way to get the index of the column A) Coumns and rows both in B should match with Cs.and Rows in A. As an example 1st column in B matches with the 1st column in A. 2nd column in B matches with the 3rd column in A. Rows should also match like that. Second row in B should match with 4th row in A. You can look at the output array to get an idea. Can someone help with atleast a part of of this quesion? Thank you.
A=[1.414151925 0 0 0 0;
1.731923552 1.224708266 0 0 0;
1.999852844 1.414171143 1.154700414 0 0;
2.236423478 1.581459133 1.291294569 1.118294021 0;
2.828219484 1.999940342 1.632993258 1.414213797 1.26461715]
B=[1.742 0 0;
2.246 1.289 0 ;
2.928 1.6329 1.414]
output= [0 0 0 0 0;
1.731923552 0 0 0 0;
0 0 0 0 0;
2.236423 0 1.291294569 0 0;
2.828219 0 1.632993258 1.414213797 0]
0 个评论
回答(1 个)
Samatha Aleti
2020-4-29
编辑:Samatha Aleti
2020-4-29
Hi,
As per my understanding you are trying to compare two matrices of different sizes with high tolerance. You can use the function “ismembertol” to do this. This function allows you to specify the tolerance value and compares accordingly.
Here is a piece of code:
output = zeros(size(A)); % Initialize
tol = 0.01; % Tolerance value
comp = ismembertol(A(4,:),B(2,:), tol); % compare 4th row of "A" with 2nd row of "B"
output(4,comp) = A(4,comp) % Assign output value
You can extend this logic for all rows & columns accordingly.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!