How can I sort and match rows of cell arrays with multiple elements?

2 次查看(过去 30 天)
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!

回答(1 个)

the cyclist
the cyclist 2017-1-13
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 个评论
Syed Wafa
Syed Wafa 2017-1-13
The problem I am facing is in elements where there are multiple numbers. I need to parse the numbers in such elements in order to match them.
the cyclist
the cyclist 2017-1-13
编辑:the cyclist 2017-1-13
Sorry, I did not look closely enough. I did not realize that the elements were not exactly equivalent between the two arrays.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by