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: Rik
Subject: Re: bin2dec behavior different from Matlab?
Date: Fri, 16 Mar 2012 17:38:44 -0700

On 03/16/2012 04:53 PM, Daniel J Sebald wrote:
>
>> One can do this.  In general, cellstr are slower than using indexing on
>> character arrays.  I tried the following and it works
>>
>> s = char (strrep (cellstr (s), " ", ""));
>> s = strjust (s, "right");
>
>
> Why is strjust necessary here?
> If the white space is removed from the string the string will already be
> justified as a consequence.  Remove the strjust() command and benchmark
> again.
The algorithm depends on the character matrix being right justified.  The
char function produces a left-justified matrix.  Try 'char ("1", "111")' as
an example.

>
> Also, strrep may not be so efficient because it is general.  It works
> with two strings.  This process is only interested in the one character '
> ', so the isspace or != test might prove much faster.
You can use indexing for deletion within ordinary arrays but not for cell
strings.  Try ' cstr = {"1 0 1"; "1"}; cstr(isspace(cstr)) = "" ' and it
will simply error out.  regexprep() would work but it is slower that strrep.
>
> Also, there may be a technique of using cellfun instead of converting
> back to char that can save time.
I've benchmarked cellfun many times and it is slower than straight indexing.
>
> There are a lot of optimization methods to explore here.
Feel free to improve the code.  It is available in Mercurial.  The
changeset is 14472:e995b1c97e13.

To create a test matrix I used

tvec = char (randi ([48 49], 1e6, 10));
tvec(randi(1e7, 1e6,1)) = " ";

which creates 1 million 10 digit binary numbers with about 10% of the
values being spaces.

--Rik



reply via email to

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