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!
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!