How can I sort and match rows of cell arrays with multiple elements?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 2 cell arrays, A1 (20812x16) and A2 (25906x12). The 1st column of A2 just has numbers (for example, 98; 55; 110; 25; 66; 11569; 8898; 13). The 15th column of A1 can have dots, numbers or multiple numbers (for example, '110'; '.'; '23,98,20'; '11569'; '.'; '13,1158898,78'; '43'; '66'; '345375,345376'). I want to match each row of A1 with that of A2 (for example, rows 1, 3, 5 and 6 of A2 would match with rows 2, 1, 5, 4 of A1) and also have the respective indices in order to make comparisons between columns. There may be some rows in A1 that do not correspond with any row in A2 (and vice-versa) and these need to be removed from the data sets.
I would be very grateful if someone could help me with this! Thank you!
0 comentarios
Respuestas (1)
the cyclist
el 13 de En. de 2017
I think at the core of what you want to do will be the statement
[tf loc] = ismember(A1(:,1),A2(:,1));
tf will indicate whether each element of the first column of A1 is present in A2, and loc will give you think index (or a 0 if it is not present). See the documentation for ismember for details.
2 comentarios
the cyclist
el 13 de En. de 2017
Editada: the cyclist
el 13 de En. de 2017
Sorry, I did not look closely enough. I did not realize that the elements were not exactly equivalent between the two arrays.
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!