필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Syed Wafa
Syed Wafa 2017년 1월 13일
편집: Syed Wafa 2017년 1월 13일
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