Fast String to Double Conversion

Version 1.8.0.0 (16.7 KB) by Quant Guy
str2doubleq converts text to double like Matlab's str2double,but up to 400x faster! multithreaded.
5.2K Downloads
Updated 10 Oct 2012

View License

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.

Installation:

*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)

Cite As

Quant Guy (2024). 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
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

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!
Version Published Release Notes
1.8.0.0

*Fixed a bug with scientific notation. Thanks for the feedback.

1.7.0.0

-Implemented "hand massaged" highly efficient parser.
-Added support to parse also complex numbers
-Restructured code to being more neat

1.3.0.0

* Thanks to Jan Simons feedback, fixed some bugs and documentation. Also was able to tweak about 35% performance boost compared to earlier implementation.

1.0.0.0