× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Change default numeric type to float in matlab

Ray Phan
Jun 24, 2015
<p>No, there is currently no way to change the default numeric type to <code>float / single</code>. See these informative posts on MathWorks forums: </p> <ul> <li><a href="http://www.mathworks.com/matlabcentral/answers/8727-single-precision-by-default-lots-of-auxiliary-variables-to-cast" rel="nofollow">http://www.mathworks.com/matlabcentral/answers/8727-single-precision-by-default-lots-of-auxiliary-variables-to-cast</a></li> <li><a href="http://www.mathworks.com/matlabcentral/answers/9591-is-there-a-way-to-change-matlab-defaults-so-that-all-workspace-floating-point-values-to-be-stored-i" rel="nofollow">http://www.mathworks.com/matlabcentral/answers/9591-is-there-a-way-to-change-matlab-defaults-so-that-all-workspace-floating-point-values-to-be-stored-i</a></li> </ul> <p>Also, quoting John D'Errico on the first link I referenced - a formidable and legendary MATLAB expert:</p> <blockquote> <p>This is not possible in MATLAB. Anyway, it is rarely a good idea to work in <code>single</code>. It is actually slower in many cases anyway. The memory saved is hardly worth it compared to the risk of the loss in precision. If you absolutely must, use <code>single</code> on only the largest arrays.</p> </blockquote> <p>As such, you should probably consider reformulating your algorithm if you are using so much memory. If you are solving linear systems that are quite large and there are many zero coefficients, consider using <a href="http://www.mathworks.com/help/matlab/ref/sparse.html" rel="nofollow"><code>sparse</code></a> to reduce your memory requirements.</p> <hr> <p>Besides which, doing this would be dangerous because there may be functions in other toolboxes that rely on the fact that <code>double</code> type allocation of matrices is assumed and spontaneously changing these to <code>single</code> may have unintended consequences.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/31019594/Change%20default%20numeric%20type%20to%20float%20in%20matlab/31019924">Stack Overflow</a>.</p>
comments powered by Disqus