help-octave
[Top][All Lists]

 From: Mirek Kwasniak Subject: Re: Indirect Addressing Question Date: Wed, 14 Nov 2001 21:55:01 +0100 User-agent: Mutt/1.3.23i

```Hi,

I have an alternative to Etienne. I solved Andreas problem this way:

[qv qcount] = count_unique(q(1:5));
a(qv)=a(qv)+10.*qcount

Where count_unique is defined as below:

function [ y, count ] = count_unique( x )

if length(x)==0;
y=[];
return;
end;

y = sort( x );
i = find( diff( [ inf; y(:) ] ) ~= 0 ) ;
y = y( i );

if nargout > 1
count = diff([ i(:); length(x)+1 ]);
count = reshape( count, size(y) );
end

It is maybe not so universal (works only on vectors) but I use
count_unique for many similar problems.

Mirek

-------------------------------------------------------------
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
-------------------------------------------------------------

```