help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem on bin2dec


From: frank wang
Subject: Re: problem on bin2dec
Date: Tue, 8 Aug 2006 11:53:40 -0700

Thank you all for the quick help.
 
The best way to solve my problem is using bi2de. Since my data size is 8x117, if I use
bin2dec(sprintf('%d',xx')) in octave, it will generate a big number such as 2.9043e+281. I know that I can use a for loop, but it will be slow and need to change matlab code.
 
Frank Wang

 
On 8/8/06, Hall, Benjamin <address@hidden> wrote:
 
-----Original Message-----
From: address@hidden [mailto:address@hidden]On Behalf Of frank wang
Sent: Tuesday, August 08, 2006 12:53 PM
To: address@hidden
Subject: problem on bin2dec

Hi,
 
I have a matlab code that convert binary to decimal. For example,
 
a=num2str([ 1 1 1 0]);
b=bin2dec(a);
ans=14.
 
However, on Octave,
 
bin2dec(num2str([1 1 1 0]))
ans = 584.
 
How could I fix this? My data set is quite big.
 
Thanks
 
Frank 
 
This is a (new) Matlab issue...Matlab 6.5.1 returns 584 whereas Matlab 2006a returns 14.  The issue is how bin2dec interprets spaces in the string.  Older versions of Matlab interpreted those spaces as 0's, so Octave did the same.  Now Matlab has changed its convention, so you are getting a different answer.
 
An easy fix is to replace num2str with something more explicit, such as
 
bin2dec( sprintf('%d',[1 1 1 0]) )
 
which should return 14 regardless of which version of Matlab or octave you run.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]