help-octave
[Top][All Lists]
Advanced

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

Re: vectorization


From: Dave Cottingham 2
Subject: Re: vectorization
Date: Sun, 11 Jan 2015 09:13:56 -0800 (PST)

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.




--
View this message in context: 
http://octave.1599824.n4.nabble.com/vectorization-tp4668064p4668066.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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