help-octave
[Top][All Lists]
Advanced

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

RE: problem on bin2dec


From: Hall, Benjamin
Subject: RE: problem on bin2dec
Date: Tue, 8 Aug 2006 13:11:47 -0400

 
-----Original Message-----
From: address@hidden [mailto:address@hiddenOn 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]