Find matching indexes in two different size arrays

30 visualizaciones (últimos 30 días)
Dinu Th.
Dinu Th. el 26 de Abr. de 2020
Comentada: Dinu Th. el 30 de Abr. de 2020
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]

Respuestas (1)

Samatha Aleti
Samatha Aleti el 29 de Abr. de 2020
Editada: Samatha Aleti el 29 de Abr. de 2020
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.
  1 comentario
Dinu Th.
Dinu Th. el 30 de Abr. de 2020
That is not what I want exactly. Because in reality I do not know the matching rows and columns in A. I have B. I need to write a code to search through the array A to find the indices that matches with B. But it should follow that row and column rule that I descibed before. But your answer gave me an idea. Thank you very much.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by