Merging rows sharing a value in a column

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 Comments

Can you provide a .mat file with the cell array?
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?
I've attached mat files of what i'd like the function to do.

Sign in to comment.

Answers (1)

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?"

Categories

Asked:

on 16 Aug 2018

Answered:

on 17 Aug 2018

Community Treasure Hunt

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

Start Hunting!