MATLAB: Insert values of arrays in another cell array

cell arrays

I have the following problem. In the attached picture I three columns of cells. My goal is to append the 2nd and 3rd column inside the first column. So in the end I will end up with only one column and the size of all cells inside will be rows x 19 double. where the 18th column comes from my original column2 and the 19th column comes from my original column3. How can I do this?

Best Answer

Use a loop (or arrayfun):
result = cell(size(gencostSorted_New, 1), 1);
for row = 1 : size(gencostSorted_New)
result{row} = [gencostSorted_new{row, :}];
end
Or
result = arrayfun(@(row) [gencostSorted_new{row, :}], 1:size(gencostSorted_new), 'UniformOutput', false);
The clever bit is the [gencostSorted_New{row, :}] which concatenate all the cells of a row into a matrix.