Search code examples
matlabinsertcell-array

insert element at specific position in cell array in Matlab


I've the following cell array:

a = {'a', 'b', 'c', 'd'}

How can I insert another string in a specific position? For example I want to put '1' string at position 3, in order to obtain:

a = {'a', 'b', '1', 'c', 'd'}

Solution

  • It can be done the same way as in matrices:

    a = {a{1:2}, '1', a{3:end}}