How about this:
x = { [] [ 82.1000] [ 16.1500] [ 56.0200] [] [ 74.9600] [ 35.1400] }; x_sorted = [cell(sum(cellfun(@isempty,x)),1) ; num2cell(sort(cell2mat(x)))]
Result:
x_sorted = [] [] [16.15] [35.14] [56.02] [74.96] [ 82.1]
First, we convert the array of cells into a vector of values, sort them, and then return them back as an array of cells. Finally, we add the original number of empty cells at the beginning, as cell2mat
ignores them in this case.
Amro source share