File Exchange

image thumbnail

Faster alternative to builtin str2double

version 1.0.0.0 (12.6 KB) by Felipe G. Nievinski
str2doubles converts character string to double number faster than the builtin str2double.

4 Downloads

Updated 20 Feb 2017

View License

This is a patched version of @Quant Guy's str2doubleq.cpp (submission #28893, last time updated five years ago). It includes a fix for memory leak indicated by @Jonathan and @Matthew Gunn in the comments. It also offers str2doubles.m, an interpreted language alternative to the mex (no compilation necessary) as given by @Jan Simon. Both .cpp and .m are slightly improved to deal with missing data. (Notice the mex version always returns complex-valued output, which doubles the storage; use wrapper str2doubleq2.m to discard all-zero imaginary component.)

Cite As

Felipe G. Nievinski (2020). Faster alternative to builtin str2double (https://www.mathworks.com/matlabcentral/fileexchange/61652-faster-alternative-to-builtin-str2double), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

Ivar Eskerud Smith

Just as James Tursa reported I also get a buildup of memory when using this function a lot, there seems to be a memory leak

juanmcloaiza

str2doubles throws an ERROR... :(

-----
In an assignment A(I) = B, the number of elements in B and I must be the same.

Error in str2doubles (line 13)
y(idx) = y2;
-----

James Tursa

Note that you still have memory leaks with these lines since you don't mxFree(s):

s = mxArrayToString(cell);

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Fast String to Double Conversion

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!