MATLAB: Need to convert from cell to numeric matrix of the same size

convert cell array to matrix

I have C= 5×1 cell array. need to convert it to a numeric matrix. I am executing the following 3 commands and attaching their outputs. what I need is output of E but with the size same as C. struggling for a couple of hours now.
D=str2double(C)
E=cell2mat(C)
F=str2num(C)
C =
5×1 cell array
{[ 25]}
{[ 35]}
{[ 40]}
{[ 35]}
{0×0 double}
D =
NaN
NaN
NaN
NaN
NaN
E =
25
35
40
35
Error using str2num (line 31) Requires character vector or array input.
>> whos C D E F Name Size Bytes Class Attributes
C 5x1 488 cell
D 5x1 40 double
E 4x1 32 double

Best Answer

You need to fill empty cells with something if you don't want the removed.
C={25;35;40;35;[]}
C_empty=cellfun('isempty',C);%much faster than cellfun(@isempty,C)
C_copy=C;
C_copy(C_empty)={NaN};%fill empty cells with a double
E=cell2mat(C_copy);
You can also use isnan on the result to process it.