Merging rows sharing a value in a column

조회 수: 2 (최근 30일)
Mina Ghbrial
Mina Ghbrial 2018년 8월 16일
답변: Image Analyst 2018년 8월 17일
EDIT: I've posted mat files of what the inputs and outputs should look like
I have this array
sharedcell =
7×3 cell array
'X' ' Uncondtone_Single' ' Condtone_Single…'
'13a' {1×2 cell} []
'13b' {1×2 cell} []
'13c' {1×2 cell} []
'13a' [] {1×3 cell}
'13b' [] {1×3 cell}
'13c' [] {1×3 cell}
I would like to merge rows containing the same identifier (13a,13b,13c) in column 1, so that I end up with this
'X' ' Uncondtone_Single' ' Condtone_Single…'
'13a' {1×2 cell} {1×3 cell}
'13b' {1×2 cell} {1×3 cell}
'13c' {1×2 cell} {1×3 cell}
I am familiar with the function unique(), but am not sure how I can use it to achieve this result.
  댓글 수: 3
Adam Danz
Adam Danz 2018년 8월 17일
It's not clear what you mean by 'merge'. For example, both of your arrays have data for 13a in column 2. Are we to assume that duplicates such as this are all identical data sets?
In other words, are you just trying to fill in the empty elements of your first cell with the data from your 2nd cell?
Mina Ghbrial
Mina Ghbrial 2018년 8월 17일
I've attached mat files of what i'd like the function to do.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 8월 17일
There is only one input array. I think she means to go down that array, and if the first row containing a unique value from column 1 is empty in any of the other columns, and the current row with the same column 1 value is NOT empty, then transfer the element from the non-empty cell on the current row to the empty cell in the same column of the first occurring row. Thus the non-empty cells in rows 5,6,7 of column 4 will get transferred to (replace) the empty cells in rows 2,3,4 of column 4, then finally delete rows 5,6,7.
Then mina said (in a now-deleted answer) "Thank you for your help. As mentioned in a comment above, the duplicates may not necessarily be empty. I want to find unique id's in column one, then find any duplicates and merge the contents of column 2 and 3 of any rows with the same id's together"
So I'm replying: "What do you do if the rows with 13a in column 1 are all fully populated in the other columns? Which do you keep?"

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by