MATLAB Answers

Combine 2 Cell Matrices into One

1 view (last 30 days)
Ruger28
Ruger28 on 6 May 2020
Commented: Star Strider on 6 May 2020
Hello,
Im trying to combine data from two matrices into one. An example:
A = {'A','B','C';'A','B','C'};
B = {'1','1','1';'2','2','2'};
and I want C to be:
C = {'A1','B1','C1';'A2','B2','C2'};
I feel like this is trivial, and I am definitely missing something. Any help would be greatly appreciated.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 6 May 2020
Try this:
A = {'A','B','C';'A','B','C'};
B = {'1','1','1';'2','2','2'};
C = cellfun(@(x,y)[x,y], A, B, 'Uni',0)
producing:
C =
2×3 cell array
{'A1'} {'B1'} {'C1'}
{'A2'} {'B2'} {'C2'}
.

  2 Comments

Ruger28
Ruger28 on 6 May 2020
Thank you very much! I was definitely going the wrong direction. I apprecaite the help!
Star Strider
Star Strider on 6 May 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products


Release

R2019b