Path: news.mathworks.com!not-for-mail
From: "Daniel Robbins" <d.w.e.robbins@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: seacrhing/indexing a vector
Date: Fri, 6 Jul 2012 12:23:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <jt6lbb$14v$1@newscl01ah.mathworks.com>
Reply-To: "Daniel Robbins" <d.w.e.robbins@gmail.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1341577387 1183 172.30.248.38 (6 Jul 2012 12:23:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 6 Jul 2012 12:23:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2776992
Xref: news.mathworks.com comp.soft-sys.matlab:773160

Hi,

I am trying to index a vector so I can establish the location of a given number. So for example, if x = 5 10 15 20 25 I can search for 20 and be given teh answer that 20 is the 4th number in the vector.

In a previous code I acheieved this with the line of code:

[c index] = min(abs(g-h)); 

However if I try:

[c index] = x 

It does not work. Please can someone offer some help as to how I can search along a vector for a specific value and identify the location of the value?

Thank you
Dan