MATLAB: How to convert a matrix of cells to a regular matrix

cell arrays

Hi! I have matrix of cells that kind of looks like this:
cell = {[8.456] [] [] [9.456] [6];
[] [] [7.89] [] [6.876];
[] [5.79] [5] [] []}
I would like to convert that int a regular matrix looking like this:
mat = [8.456 0 0 9.456 6;
0 0 7.89 0 6.876;
0 5.79 5 0 0]
I have tried str2double, srt2num, cell2mat in combination with different for loops but i haven't managed to solve it yet. I would really appreciate some help with this one!

Best Answer

Without changing the original cell array:
>> C = {8.456,[],[],9.456,6;[],[],7.89,[],6.876;[],5.79,5,[],[]};
>> out = zeros(size(C));
>> out(~cellfun('isempty',C)) = [C{:}]
out =
8.45600 0.00000 0.00000 9.45600 6.00000
0.00000 0.00000 7.89000 0.00000 6.87600
0.00000 5.79000 5.00000 0.00000 0.00000
PS: If those cells really do contain strings/char vectors, then use:
idx = ~cellfun('isempty',C);
out = zeros(size(C));
out(idx) = str2double(C(idx))