help-octave
[Top][All Lists]
Advanced

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

Re: Getting the index of a vector element with a given value?


From: bharat pathak
Subject: Re: Getting the index of a vector element with a given value?
Date: Fri, 18 Jul 2008 15:17:13 +0530

just issue a find command.

index = find(vector == value)

bharat pathak

Arithos Designs
www.Arithos.com

DSP Design Consultancy and Corporate Training Company : Bangalore (India).




--------------------------------------------------
From: "Primoz PETERLIN" <address@hidden>
Sent: Friday, July 18, 2008 2:54 PM
To: <address@hidden>
Subject: Getting the index of a vector element with a given value?

Hello again,

Another question. Suppose I have a vector of values, and would want to
know the indices of the elements of this vector have a given value.
What is the easiest way to get them? I came up with the following:

function indices = vindex(vec, value)
 indices = [];
 for i = 1:length(vec)
   if (vec(i) == value)
     indices = [indices, i];
   endif
 endfor
 if (length(indices) == 0)
   indices = 0;
 endif
endfunction

Does anything more general and faster exist already? I am aware of
find(), which returns the indices of nonzero elements, and index(),
which performs a similar task on strings (although the latter only
returns the index of the first element).

TIA, Primož

_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave


No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.5.1/1559 - Release Date: 17-07-2008 18:08




reply via email to

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