How to set Matlab precision to Single

my code requires a precision 32 bit float. Matlab uses double by default, is there a way to set it to single by default so that when ever my program executes , all my variables are in single

Réponses (3)

Walter Roberson
Walter Roberson le 31 Août 2012
This information can be found in http://undocumentedmatlab.com. My memory is that it is
system_specific('precision', '24')
but you should check.
However, it should definitely not be trusted that all internal calculations will be made in single precision even if all the variables involved are single precision.

4 commentaires

Star Strider
Star Strider le 31 Août 2012
Modifié(e) : Star Strider le 31 Août 2012
I couldn't find a ‘system_specific’ command mentioned when I looked on that site just now. There were a few mentions on a Web search (none later than 2010), but nothing else about it related to MATLAB. When I typed system_specific at the command line (Windows 7, 2012a), I got:
Undefined function or variable 'system_specific'.
It would be nice if a few such customization functions existed, though.
Walter Roberson
Walter Roberson le 31 Août 2012
Thank you! (Bookmarked for later reference.)
An experimental system_dependent() call generated no errors (or to the best of my knowledge, anything else), and a feature() call generated:
Error using feature
Not enough input arguments.
I was hoping that both calls would generate some documentation themselves, but no such luck. I don't surf Undocumented MATLAB much because it seems to be mostly Java. I may need to visit it more often.
Jan
Jan le 1 Sep 2012
The command is: feature('SetPrecision', 24). The deafult value is 53, which means standard 64 bit DOUBLE precision, while 64 enables the storing of intermediate values in the 80 bit registers of Intel processors.
But this command enables rounding to single precision. This is useful to check the numerical precision of an algorithm, but it neither saves time nor memory. Therefore I assume, that this is not useful for you. Please explain, what you are wanting to achieve.

Connectez-vous pour commenter.

Azzi Abdelmalek
Azzi Abdelmalek le 31 Août 2012
single(x)

2 commentaires

Pratheek
Pratheek le 31 Août 2012
i want all my variable to work automatically with single precision, not by casting
Azzi Abdelmalek
Azzi Abdelmalek le 31 Août 2012
Modifié(e) : Azzi Abdelmalek le 31 Août 2012
if your data are single , all your variables will be single
a=single(2)% single
b=14 % double
c=a*b % single

Connectez-vous pour commenter.

Star Strider
Star Strider le 31 Août 2012

0 votes

The best you can likely do is described in this thread ‘Single Precision by Default? ... lots of auxiliary variables to cast’ last year.

Produits

Question posée :

le 31 Août 2012

Community Treasure Hunt

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

Start Hunting!

Translated by