help-octave
[Top][All Lists]

## Re: Indirect Addressing Question

 From: adler Subject: Re: Indirect Addressing Question Date: Thu, 15 Nov 2001 22:16:10 -0500 (EST)

```On Wed, 14 Nov 2001, Paul Kienzle wrote:
> Here is yet another solution, but it requires Andy Adler's sparse functions
> from
> octave-forge:
>
>     q = [1:10];
>     idx = [5,1,1,1,2,2];
>     projection = sum(sparse(1:length(idx),idx,q(idx)+10));
>     used = find(projection);
>     q(used) = projection(used);
>     q
> q =
>
>   33  24   3   4  15   6   7   8   9  10

There's a more direct way of doing this with sparse:

q = [1:10];
idx = [5,1,1,1,2,2];
[i,j,v]=spfind( sparse(1,idx,q(idx)+10,1,5,'sum') );
q(j)=v
q =
33  24   3   4  15   6   7   8   9  10

I introduced the "sum" mode on the suggestion of
Andreas Stahel <address@hidden>, as
a nice way to simplify some FEM problems.
_______________________________________

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```

reply via email to