From: Benoit on
Hello,

Is there a function is MATLAB that decomposes a numbers as follows:

[a b c d] = function(258.2)

where a = 2; b = 5; c = 8; and d = 2?

Thank you for your help,

Ben
From: Steven Lord on

"Benoit " <igneben(a)gmail.com> wrote in message
news:hu5pva$b2a$1(a)fred.mathworks.com...
> Hello,
>
> Is there a function is MATLAB that decomposes a numbers as follows:
>
> [a b c d] = function(258.2)
>
> where a = 2; b = 5; c = 8; and d = 2?

Be careful ... 258.2 is not exactly two hundred fifty-eight and two tenths.
It's the closest IEEE double precision floating-point number to two hundred
fifty-eight and two tenths.

If you're willing to accept the approximation, SPRINTF the number using an
appropriate format string then delete the '.' character from the string.

s = sprintf('%3.1f', 258.2)
s(s=='.') = []
abcd = s-'0'

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Benoit on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hu5qfm$g4h$1(a)fred.mathworks.com>...
>
> "Benoit " <igneben(a)gmail.com> wrote in message
> news:hu5pva$b2a$1(a)fred.mathworks.com...
> > Hello,
> >
> > Is there a function is MATLAB that decomposes a numbers as follows:
> >
> > [a b c d] = function(258.2)
> >
> > where a = 2; b = 5; c = 8; and d = 2?
>
> Be careful ... 258.2 is not exactly two hundred fifty-eight and two tenths.
> It's the closest IEEE double precision floating-point number to two hundred
> fifty-eight and two tenths.
>
> If you're willing to accept the approximation, SPRINTF the number using an
> appropriate format string then delete the '.' character from the string.
>
> s = sprintf('%3.1f', 258.2)
> s(s=='.') = []
> abcd = s-'0'
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
>

Dear Steve,

Thank you for your answer. This is exactly what I wanted.

Ben