[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: logical indexing shortcut?
From: |
Andreas Weber |
Subject: |
Re: logical indexing shortcut? |
Date: |
Sun, 3 Sep 2017 18:16:20 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
Am 03.09.2017 um 18:02 schrieb Peter P.:
> I am looking for a way to operate on certain elements of a vector using
> logical indexing. I want to multiply all elements in x that are integer
> multiples of four by the number 5.
>
> x = [3 15 9 12 -1 0 -12 9 6 1];
> b = rem(x, 4)==0;
> x(b) = x(b)*5
>
> I wonder if there is a way to do it in one step, without creating index
> vector b?
x(!rem(x, 4))*=5
HTH, Andy