help-octave
[Top][All Lists]

Re: Wrong indices returned using Lookup for cells containing strings

 From: Nicholas Jankowski Subject: Re: Wrong indices returned using Lookup for cells containing strings Date: Tue, 20 Oct 2015 08:25:21 -0400

On Tue, Oct 20, 2015 at 8:06 AM, Olaf Till wrote:
On Tue, Oct 20, 2015 at 02:37:15AM -0700, rcharan51 wrote:
> i have two cell arrays(strings) of size 20X1 and 3X1. when i tried to lookup
> larger cell array in the shorter one the indices returned are not correct.
> My guess is that since the cells in the short array are not sorted in any
> particular order, wrong indices are returned. Am i right? if so what is work
> around for this?
> any help is much appreciated. Thanks.
>
> >> b=geo_ch(1:20, 1)
> b =
> {
>   [1,1] = GEN
>   [2,1] = GEN
>   [3,1] = GEN
>   [4,1] = GEN
>   [5,1] = GEN
>   [6,1] = GEN
>   [7,1] = GEN
>   [8,1] = GEN
>   [9,1] = GEN
>   [10,1] = GEN
>   [11,1] = GEN
>   [12,1] = GEN
>   [13,1] = GEN
>   [14,1] = GEN
>   [15,1] = GEN
>   [16,1] = GEN
>   [17,1] = WEAK
>   [18,1] = WEAK
>   [19,1] = WEAK
>   [20,1] = WEAK
> }
> >> a=trop1mix(4:6,1)
> a =
> {
>   [1,1] = GEN
>   [2,1] = WEAK
>   [3,1] = MIX
> }
> >> id=lookup(a,b)
> id =
>
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    1
>    3
>    3
>    3
>    3

But the above seems correct to me ... Olaf

I assume he's expecting 1's followed by 2's. I've never used lookup for non-numerical arrays, but I know it generally expects a to be monotonic. the help says for strings "lookup is performed using lexicographical comparison".  I notice his a is 'lexocographically' monotonic but b is not.  is that the source of his confusion?  Olaf, can you explain why the output of 3 should be expected, rather than the 2 he was expecting?

nickj