Fast String to Double Conversion
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)
Citar como
Quant Guy (2025). Fast String to Double Conversion (https://www.mathworks.com/matlabcentral/fileexchange/28893-fast-string-to-double-conversion), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Compatibilidad con las plataformas
Windows macOS LinuxCategorías
- MATLAB > Language Fundamentals > Data Types > Data Type Conversion >
- MATLAB > Language Fundamentals > Data Types > Characters and Strings > String Parsing >
Etiquetas
Agradecimientos
Inspiración para: Faster alternative to builtin str2double
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
Versión | Publicado | Notas de la versión | |
---|---|---|---|
1.8.0.0 | *Fixed a bug with scientific notation. Thanks for the feedback. |
||
1.7.0.0 | -Implemented "hand massaged" highly efficient parser.
|
||
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 |