help-octave
[Top][All Lists]
Advanced

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

Re: help - two different syntaxes produce different results -typo in pre


From: Carlo De Falco
Subject: Re: help - two different syntaxes produce different results -typo in previous
Date: Wed, 30 Oct 2019 13:25:31 +0000


> Il giorno 30 ott 2019, alle ore 13:30, Joe Tusek <address@hidden> ha scritto:
> 
> Hi,
>  
> When I run the following code 
>  
> v = [68   73   77   85
>    95   85  104   99
>    68  181  162   92
>    98  130  123   93
>    94   87   87   88]
>  
> [a, b]= find(v>100)
> v(a,b)= 0
>  
> av = [68   73   77   85
>    95   85  104   99
>    68  181  162   92
>    98  130  123   93
>    94   87   87   88]
>  
> [c]= find(av>100)
> av(c)= 0
>  
> The top script produces 6 cells with 0 in them and the bottom script produces 
> 5 cells with zero in them. It seems to me that these should produce the same 
> result?


No, this is the expected behaviour, when indexing a matrix with two lists of 
indices you are actually indexing a sub-block,
while when indexing it with one list of indices you are acessing it as a 
flattened linear array.

To get the same result in the two cases above you should modify the first one 
as follows:

>> v = [68   73   77   85
   95   85  104   99
   68  181  162   92
   98  130  123   93
   94   87   87   88];
>> [a, b]= find(v>100);
>> ab = sub2ind (size (v), a, b);
>> v(a,b)= 0;


>  
> I am using W10 and Oct 5.1.0.
>  
> Regards
> Joe


c.






reply via email to

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