octave-maintainers
[Top][All Lists]
Advanced

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

Re: bin2dec behavior different from Matlab?


From: Miguel Bazdresch
Subject: Re: bin2dec behavior different from Matlab?
Date: Sun, 25 Mar 2012 21:45:06 -0600
User-agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120314 Thunderbird/11.0

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).

Thanks,

--
Miguel Bazdresch


reply via email to

[Prev in Thread] Current Thread [Next in Thread]