
150 Accelerating MATLAB
®
Performance
since it places its outputs in a cell array;* str2double is even slower and the least versatile
(only accepts scalars);
†
str2num is the slowest and yet the most forgiving, accepting any
expression that evaluates to a number, including variables and functions:
value = str2num('3.141593');
⇨ Elapsed time is 0.000115 seconds.
value = str2double('3.141593');
⇨ Elapsed time is 0.000074 seconds.
cells = textscan('3.141593','%f'); value = cells{1};
⇨ Elapsed time is 0.000037 seconds.
value = sscanf('3.141593','%f');
⇨ Elapsed time is 0.000016 seconds.
Of all these alternatives, str2num and str2double are ...