str2doubleq is equivalent to the Matlab built-in str2double function that converts char or cellstr array to appropriate double arrays. The drawback of built-in str2double is that it becomes very slow when the dataset becomes larger.
str2doubleq exploits C++ fast string handling capabilities. Also if you have a compiler supporting new C++11 standard or you have Boost libraries installed on your computer, you can use the multithreaded algorithm. Multithreaded algorithm scales very well if data set is sufficiently large.
Function has been programmed exactly to the same behavior as str2double.
Original demand for the function has arisen from certain market data parsing problems that had to be done in real time. Now Matlab can be as fast as traditional programming languages in these types of string parsing problems.
*Copy the file str2doubleq.cpp somewhere in hard drive. (Example C:\Test\str2doubleq.cpp)
*Launch Matlab and compile the source file to generate machine dependent binary. If you have not selected a compiler this needs to be done first (run mex -setup in command window).
* Source is compiled typing mex <c-source folder>
(Example mex C:\Test\str2doubleq.cpp)
*Place the generated str2doubleq.mexw32 (32-bit) or str2doubleq.mexw64 (64-bit) to Matlab's scope (set path- folder group)
*If you want to increase performance even more, then uncomment the line 35 from str2doubleq.cpp (containing #define USE_PARALLEL_ALGORITHM). Remeber that you need to have modern enough compiler or Boost (http://www.boost.org/) installed.
Now you can use the function in normal matlab fashion. Run the testcases script test_str_to_double_performance.m (included in zip-file)
Quant Guy (2021). Fast String to Double Conversion (https://www.mathworks.com/matlabcentral/fileexchange/28893-fast-string-to-double-conversion), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired: Faster alternative to builtin str2double
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!