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.