help-octave
[Top][All Lists]
Advanced

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

Re: vectorization


From: Helios de Rosario
Subject: Re: vectorization
Date: Mon, 12 Jan 2015 10:05:19 +0100

>>> El día 11/01/2015 a las 10:19, Nidjara <address@hidden>
escribió:
> 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.
> 

That's a typical case of sparse matrix. Thus I'd recommend make G
sparse. You'll gain in memory usage and speed:

G = sparse(L1, L2, L3, 4, 4);

See "help sparse" for the meaning of the arguments, and look for
documentation about how to use sparse matrices in Matlab (there's more
documentation referring to Matlab than to Octave, but both interfaces
are pretty the same).

But if you really want a "full" matrix, just:

G = full( sparse(L1, L2, L3, 4, 4) );

Helios



SABEMOS QUÉ HICIMOS EN 2013
365 días de Innovación
ANUARIO DE BIOMECÁNICA
http://www.ibv.org/anuario2013
______________________________

INSTITUTO DE BIOMECÁNICA DE VALENCIA
Universidad Politécnica de Valencia • Edificio 9C
Camino de Vera s/n • 46022 VALENCIA (ESPAÑA)
Tel. +34 961111170- +34 610567200 • Fax +34 96 387 91 69
www.ibv.org

Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección
de Datos de Carácter Personal, le informamos de que el presente mensaje
contiene información confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepción no le autoriza a su divulgación
o reproducción por cualquier medio, debiendo destruirlo de inmediato,
rogándole lo notifique al remitente.




reply via email to

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