15

I have created a function which takes vectors for input variables and returns a cell array for each set of inputs. The final output variable (out) seems to consist of a 2x1 cell containing two 1x5 cells. I have provided a screenshot of this below:

Screenshot of current output

I am just trying to figure out how to flatten the cell array (out) to be a 2x5 cell array.

Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
GloveTree
  • 371
  • 1
  • 6
  • 17
  • 3
    `vertcat(cell_array1{:})` is one way. – Divakar Apr 28 '14 at 07:36
  • Thanks, that worked perfectly, I did not think of using vertcat to combine them. Although I suppose you can use : due to linear indexing. – GloveTree Apr 28 '14 at 07:40
  • 1
    @Divakar, how about adding that as an answer? In my opinion, it's better that way, even if the answer is very simple/short. As it stands, it appears to be unanswered on the front page. – Stewie Griffin Apr 28 '14 at 07:50

2 Answers2

20

One way to achieve that would be -

vertcat(cell_array1{:})
Divakar
  • 218,885
  • 19
  • 262
  • 358
  • Since this is the first google answer, I think mentioning **horzcat** could help in the horizontal way. – dEmigOd Dec 13 '18 at 09:58
5

If your cell has unequal number of elements in each row , maybe this might work better

vector=[cell_array{:}]
Rahul
  • 3,220
  • 4
  • 22
  • 28