|
From: | frank wang |
Subject: | Re: problem on bin2dec |
Date: | Tue, 8 Aug 2006 11:53:40 -0700 |
-----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 bin2decHi,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.ThanksFrankThis 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 asbin2dec( sprintf('%d',[1 1 1 0]) )which should return 14 regardless of which version of Matlab or octave you run.
[Prev in Thread] | Current Thread | [Next in Thread] |