Insert values of arrays in another cell array

5 views (last 30 days)
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?

Accepted Answer

Guillaume
Guillaume on 30 Jun 2015
Edited: Guillaume on 30 Jun 2015
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.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!