1

I have two cell arrays, cellarray1 (m x n) and cellarray2 (m x 1), and want to take cellarray2 and input this in cellarray1. However, I would like to input this in the second column, thus pushing the existing cells in cellarray1 to the right, so that the final result is a cell array with n+1 columns with the new column having pushed all columns to the right, taking place at column 2 in cellarray1. Maybe this is a strange problem, I don't know. There is no straight forward solution as I have found.

Best, Granit

Erfan
  • 1,897
  • 13
  • 23
augusti
  • 401
  • 3
  • 6
  • 16

1 Answers1

4

You can combine cell arrays using array concatenation operator, [].

Let's say cellarray1 is an M x N cell array and cellarray2 is M x P. (In your example P = 1.) You can make the result you want in this way:

cellarray1 = [cellarray1(:,1), cellarray2, cellarray1(:,2:end)];

cellarray2 is inserted in the 2nd till P+1th column of the output.

Erfan
  • 1,897
  • 13
  • 23