I need to insert a column (vector) with non-numeric data cells (one or multiple strings) into a cell of non-numeric data at an arbitrary location and retain old data columns by shifting them to the right.
my_word =
's' 'i' 'p'
's' 'i' 'p'
's' 'i' 'p'
's' 'i' 'p'
's' 'i' 'p'
my_column =
'a'
'b'
'c'
'd'
'e'
result_cell_1 =
's' 'a' 'i' 'p'
's' 'b' 'i' 'p'
's' 'c' 'i' 'p'
's' 'd' 'i' 'p'
's' 'e' 'i' 'p'
result_cell_2 =
's' 'i' 'a' 'p'
's' 'i' 'b' 'p'
's' 'i' 'c' 'p'
's' 'i' 'd' 'p'
's' 'i' 'e' 'p'
The major problem is that I want to insert a column at the second and the third location. In addition, I am not limited to the length in the example, so the solution should allow me to loop over a row of any length and insert a column at each location incrementally. Also, I have a solution for substitution each column, including the first and the last one, so they are not the problem. The problem is in the middle, where the length is not always the same.
Manipulating cell arrays is very similar to normal matrices. If
i
were the column to insert,would accomplish your goal. It breaks
my_word
into the first and second half, and concatenates them back together withmy_column
in the middle.