[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem on bin2dec
From: |
Quentin Spencer |
Subject: |
Re: problem on bin2dec |
Date: |
Tue, 08 Aug 2006 12:19:57 -0500 |
User-agent: |
Thunderbird 1.5.0.4 (X11/20060614) |
frank wang wrote:
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.
It looks like Matlab's bin2dec function was designed to ignore white
space in strings, and octave's version wasn't. I usually perform this
conversion using the bi2de function from octave-forge, which is faster
because it doesn't convert to a string first, and it works in both
Matlab and octave (I think in Matlab you have to have the communication
toolbox).
octave:1> bi2de([1,1,1,0])
ans = 7
octave:2> bi2de([1,1,1,0],'left-msb')
ans = 14
Quentin