[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vectorization
From: |
Ben Abbott |
Subject: |
Re: vectorization |
Date: |
Sun, 11 Jan 2015 13:59:55 -0500 |
> On Jan 11, 2015, at 12:13 PM, Dave Cottingham 2 <address@hidden> wrote:
>
> Nidjara wrote
>> Hi,
>>
>> I have 3 vectors (nx1) of real numbers, denote them with L1, L2, L3, and
>> (nxn) matrix G. I'm trying to vectorize the following loop:
>>
>> for i=1:n
>> G(L1(i), L2(i))=L3(i);
>> end
>>
>> but this appears not to be as simple as it seems. Can you please help.
>>
>> Thanks!
>
> One solution is to use the fact that you can index an array, which normally
> would have two indices, with a single index. So that would be something
> like
>
> G((L1 - 1) * n + L2) = L3;
>
> I may have L1 and L2 mixed up there; a little experimenting should
> straighten it out.
Or use sub2ind () ...
G(sub2ind (size (G), L1, L2)) = L3;
Ben
- vectorization, Nidjara, 2015/01/11
- Re: vectorization, Helios de Rosario, 2015/01/12
- Re: vectorization, Nidjara, 2015/01/12
- Re: vectorization, Dave Cottingham 2, 2015/01/12
- Re: vectorization, Andreas Weber, 2015/01/12
- Re: vectorization, Nidjara, 2015/01/12
- Re: vectorization, Andreas Weber, 2015/01/12
- Re: vectorization, Nidjara, 2015/01/12