Thread Subject: cast complex number into single

Subject: cast complex number into single

From: Juliette Salexa

Date: 17 Feb, 2011 02:07:03

Message: 1 of 3

Hi. In the example below, I'm trying to turn a double precision complex number into a single precision complex number. It doesn't seem to be working ... am I doing something wrong ?
================
a=rand+1i*rand;
cast(a,'single');

>> class(a)
double

% I expected it to be single

cast(real(a),'single');cast(imag(a),'single');
>> class(a)
double

>> class(imag(a))
double
================

Subject: cast complex number into single

From: Steven_Lord

Date: 17 Feb, 2011 04:17:07

Message: 2 of 3



"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message
news:ijhvs7$8dn$1@fred.mathworks.com...
> Hi. In the example below, I'm trying to turn a double precision complex
> number into a single precision complex number. It doesn't seem to be
> working ... am I doing something wrong ?
> ================
> a=rand+1i*rand;
> cast(a,'single');
>
>>> class(a)
> double
>
> % I expected it to be single

No. The CAST function returned the value in a converted to single
precision, but you threw that value away since you didn't assign it to
anything. Call it with an output argument.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: cast complex number into single

From: Juliette Salexa

Date: 17 Feb, 2011 12:41:04

Message: 3 of 3

Thanks Steve!
I should really have known that by now =(
I apologize for wasting forum space with such an ignorant question!

But thanks for pointing me in the right direction!
Juliette

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com