Search code examples
arraysmatlabvectorcell

Convert specific cell array elements to array


I have a problem when trying to convert a sequnce of cell array's elements into a matrix in Matlab. In particular, I execute the folllowing command for taking the elements I want from the cell_array[] (note that although I've put 11 as a constant here, it actually varies depending on other things but it's known when I execute the command):

cell_array{3, 2:2:11,1}

which gives the following result:

ans =
                     0.173

ans =
                     0.188

ans =
                      0.06

ans =
                     0.165

ans =
                     0.225

In order to put the above elements into an array C, I have tried using vec2mat but it didn't work:

C=vec2mat((cell_array{3, 2:2:11,1}),5)
Error using vec2mat
Too many input arguments

Also, when I try that:

C=cell_array{3, 2:2:11,1})

only the first element is strored in C:

C =
                 0.173

Any help will be appreciated. Thanks.


Solution

  • Try just

    C = [cell_array{3, 2:2:11,1}]
    

    (that is, enclose the expression inside square brackets)