-1

I am having difficulty with MATLAB. I have 106 columns and 1 row. Each cell in each row contains a different amount of numbers. If I type result{1} I get 7. If I type result{2}, I get 3 numbers, etc... How can I list all the numbers out in the column instead of having individual cells. I know I need to make a zeros matrix but I am not sure about the syntax.

Jackson Hart
  • 1,600
  • http://www.mathworks.com/help/matlab/ref/cell2mat.html –  Jan 13 '14 at 20:33
  • I already tried that: Error using cat Dimensions of matrices being concatenated are not consistent. – Jackson Hart Jan 13 '14 at 20:34
  • See if a loop helps: https://www.mathworks.com/matlabcentral/answers/20281-cell-to-matrix –  Jan 13 '14 at 20:36
  • If I try: CAT(1, C{:}), I get all the numbers in one column. Getting closer but I need them to stay in their respective columns – Jackson Hart Jan 13 '14 at 20:45
  • @user2943324 Do you have any ideas? The loop isnt working – Jackson Hart Jan 13 '14 at 21:02
  • So is the question actually: How to convert a ragged array stored in a cell array into a regular rectangular array/matrix? To answer the question we really need to know the dimensions of the the vectors/matrices of the cells of your cell array. Are they all column vectors or all row vectors? And what are the dimensions of the cell array itself (size)? In any case, this question is off-topic as it doesn't relate to mathematics but rather to programming. You can ask such questions at StackOverflow/Matlab. – horchler Jan 13 '14 at 21:47

2 Answers2

1

Maybe you could 1) Find the maximal number of numbers. 2) Append the missing number of numbers (zeros) to each cell. 3) Use cell2mat.

This may be wasteful, of course, if there are lots of zeros.

user66081
  • 3,987
  • 17
  • 29
1

If I understand your question correctly:

>> myCell = {1,[2 3 4],[10 11]}; %// for example
>> [myCell{:}]
ans =
     1     2     3     4    10    11
Luis Mendo
  • 1,834