|
From: | Rik |
Subject: | Re: Matlab quirks |
Date: | Mon, 26 Mar 2012 09:19:29 -0700 |
On 03/26/2012 06:41 AM, address@hidden wrote:
This isn't true. Matlab has lots of quirks. Only because they are the 800 pound gorilla in this space is their behavior accepted as the norm rather than being seen as difficult or obtuse. This thread began because bin2dec in Octave was treating spaces differently than Matlab. But Matlab itself has flipped and flopped on the desired behavior. The release notes for Matlab 7 (R14) available here (http://www.mathworks.com/help/techdoc/rn/f8-1009921.html) note that they decided to change the treatment of spaces.Message: 3 Date: Sun, 25 Mar 2012 21:45:06 -0600 From: Miguel Bazdresch <address@hidden> To: ahowe42 <address@hidden> Cc: address@hidden Subject: Re: bin2dec behavior different from Matlab? Message-ID: <address@hidden> Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 03/22/2012 02:31 AM, ahowe42 wrote:Miguel Instead of having your students learn num2str, you could show them how sprintf works. Since this comes from C, it's widely applicable and gives more control. For the specific issue here, if x is a logical array, you can do this: xstr = sprintf("%d",x) then bin2dec(xstr) is 5 as expected.Andrew, You are right, of course, that sprintf may be a better command to use in many cases. I already tell them about 'char' which is also a nice command to know. I will consider telling them about sprintf too. Since these are four-year students, though, I try to teach them to find by themselves the commands they need in a particular situation. They very often find 'num2str' and use it. Also, it would sound bad to tell them not to use 'num2str' because, you know, it has some quirks (and Matlab, by the way, does not). --- Excerpt of release notes --- bin2dec Ignores Space CharactersThe bin2dec function now ignores any space (' ') characters in the input string. Thus, the binary string '010 111' now yields the same result as the string '010111'. In Release 13, bin2dec interpreted space characters as zeros: bin2dec('010 111') ans = 39 In this release, bin2dec ignores all space characters: bin2dec('010 111') ans = 23--- end of excerpt --- So Octave was compatible with Matlab, then Matlab changed their behavior and Octave became incompatible, and now Octave has been modified to restore compatibility. There was never any quirkiness or bad programming in Octave on this issue. --Rik |
[Prev in Thread] | Current Thread | [Next in Thread] |