MATLAB: Sscanf in a cell array

cell arraysscanfstr2double

good morning, I have a cell array (of strings) and I want to replace strings with corresponding numbers, but using str2double that is incredibly slow. They suggested me to use
sscanf
instead, but I'm not able to use it in a cell array. Any suggestions? Thanks
let's take for instance, [{'0.001'},{'0.34'};{'89'},{'34'};{'0.898'},{'988'}]
and use sscanf

Best Answer

Using sscanf will be faster than using str2double in a cell array:
C = {'0.001','0.34'; '89','34'; '0.898','988'};
cellfun(@(s)sscanf(s,'%f'), C)
This defines an anonymous function , which is then called by cellfun for each string in the cell array C.
EDIT: Based on Guillaume's Answer and my own tests, the fastest conversion that I could achieve (I don't have strjoin) was using array preallocation and a loop, like this:
X = nan(size(C));
for k = 1:numel(X)
X(k) = sscanf(C{k},'%f');
end