Sort and add value from same neighbour value
Show older comments
I have a calculation problem and need anyone help to solve it.
out =
'Q7' [ 0] 'Q12G' [ 0] 'Q12G' [ 0] 'Q7' [ 0] 'Q12G' [ 0] 'Q12G' [ 0]
'Q12H' [-3] 'Q12L' [-3] [] [] [] [] [] [] [] []
1. I have 12 columns. First, I want to combine column 1&2,5&6,9&10 in cell A
A=
'Q7' [ 0]
'Q12H' [-3]
'Q12G' [ 0]
[] []
'Q12G' [ 0]
[] []
2. Then, I want to combine column 3&4,7&8,11&12 in cell B
B=
'Q12G' [ 0]
'Q12L' [-3]
'Q7' [ 0]
[] []
'Q12G' [ 0]
[] []
My question is, can we sort cell A and B, then add right column values of same left column values, and merge them become one value only instead of occur multiple times.
The output will become like this.
newA=
'Q7' [0]
'Q12H' [-3]
'Q12G' [0]
newB=
'Q12G' [0]
'Q12L' [-3]
'Q7' [0]
Thank you for your help.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!