double to float

  • Follow


Hi,
I am having some issues with memory and it was suggested to me that I try converting the contents of my matrices from double to float. I've tried other memory management techniques and most don't work for my situation. 

Is it possible to convert the contents of an entire matrix into float? I tried using the float command but am getting the following error:

??? Input argument "ExpBits" is undefined. 

Error in ==> float at 49
       DataType=
       struct('Class', 'FLOAT', 'MantBits', (TotalBits-ExpBits-1), 'ExpBits', Expbits);

Thank you!
0
Reply Andy 7/14/2010 10:57:12 PM

M_double = double(magic(10)./10);
whos('M_double');
M_single=single(M_double);
whos('M_single');
0
Reply Michael 7/14/2010 11:20:05 PM


Dear Andy,

as Michael has mentioned already: "Floats" are called "single" in Matlab.
See "help float".

Jan
0
Reply Jan 7/15/2010 7:48:05 AM

"Andy " <dcg48@cornell.edu> wrote in message <i1lfc8$co5$1@fred.mathworks.com>...
> Hi,
> I am having some issues with memory and it was suggested to me that I try converting the contents of my matrices from double to float. I've tried other memory management techniques and most don't work for my situation. 
> 
> Is it possible to convert the contents of an entire matrix into float? I tried using the float command but am getting the following error:
> 
> ??? Input argument "ExpBits" is undefined. 
> 
> Error in ==> float at 49
>        DataType=
>        struct('Class', 'FLOAT', 'MantBits', (TotalBits-ExpBits-1), 'ExpBits', Expbits);
> 
> Thank you!

well... according to the error message, you simply forgot the second input arg...

     r=float(pi,64)
%{
%    r =
          Class: 'FLOAT'
          MantBits: -61.858
          ExpBits: 64
%}

us
0
Reply us 7/15/2010 8:20:05 AM

"Andy " <dcg48@cornell.edu> wrote in message <i1lfc8$co5$1@fred.mathworks.com>...
> Hi,
> I am having some issues with memory and it was suggested to me that I try converting the contents of my matrices from double to float. I've tried other memory management techniques and most don't work for my situation. 
> 
> Is it possible to convert the contents of an entire matrix into float? I tried using the float command but am getting the following error:
> 
> ??? Input argument "ExpBits" is undefined. 
> 
> Error in ==> float at 49
>        DataType=
>        struct('Class', 'FLOAT', 'MantBits', (TotalBits-ExpBits-1), 'ExpBits', Expbits);
> 
> Thank you!

There is confusion in the naming of floating types here.  The smallest floating type (a.k.a. single precision) is "float" in C, "REAL" in FORTRAN and "single" in Matlab.

Matlab's default type: "double" is "double" in C, "DOUBLE PRECISION" in FORTRAN.

To confuse things further, Matlab provides a "float" function, which does not (as might be expected by an experienced C programmer) cast an arbitrary floating type to a single precision float.
0
Reply Steve 7/15/2010 9:30:09 AM

4 Replies
175 Views

(page loaded in 0.265 seconds)

Similiar Articles:













7/26/2012 10:09:48 PM


Reply: