1
votes

I have a matrix B (1 * 5 cell) I want to change it to B (5 * 1 cell) knowing that each element of the matrix contains (1 * 18 cell) and each is a cell

original matrix

        [1]           [2]        [3]           [4]          [5]`
[1] (1*18 cell)   (1*18 cell)   (1*18 cell) (1*18 cell)  (1*18 cell)

My goal is:

1) convert line from B to column% I try to use C = A (:); And C = B. '

2) make B a cellless matrix with cell2mat% Error using cell2mat (line 53) Can not support cell arrays containing cell arrays or objects.

The desired output is:

        [1]  [2]   [3]    [4]    [5]    [6]   [7]   [8]    [9]   [10]   [11]  ... [18]  
    [1] 2    1.5   1.69   1.02   1      1.36  1     2      1.67  1.20   1.36  ...     
    [2] 2    1.53  1.99   1      1.36   1     2     1      1     1.99   1.02 ...     
    [3] 1.02 1     1.36   1.3    2      1.67  1.20  1.36   1.99  2      1.5  ...  
    [4] 2    1.53  1.99   1      1.36   1     2     1      1     1.36   1.99 ...   
    [5] 1.5  1.69  1.02   1.2    1.36   1     2     1      1.36   1.5   1.5 ...

thanks

1

1 Answers

2
votes

You can just use cat (combined with {} indexing to create a comma-separated list) to concatenate all of the cell arrays in B along the first dimension

out = cat(1, B{:});

If you want the result to no longer be a cell, use cell2mat on the output

cell2mat(out)