Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: shifting data within a vector
Date: Mon, 5 May 2008 23:28:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <fvo564$i8p$1@fred.mathworks.com>
References: <fvo3dr$8qk$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210030084 18713 172.30.248.35 (5 May 2008 23:28:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 5 May 2008 23:28:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:466800



"Hydroman S" <amirgsalem@gmail.com> wrote in message <fvo3dr$8qk
$1@fred.mathworks.com>...
> For a vector s, I found its maximum value, and located it
> 
> s=rand(20,1);
> max(s);
> find(s==max(s));
> 
> 
> Now I want to add a value of say x=10; to the max(s) and 
> place it in the following row(raw after max(s)), then add 
> a value of 20 to the max(s)and add it to the following 
> raw....etc till the end raw?
> 
> Any suggestions?  
-----------
  First of all, you don't need 'find' here.  Just use the index returned by max:

 [mx,ix] = max(s); % ix is the index of the maximum element of x

  The rest of what you are asking is rather hard to interpret.  Your misuse of 
the word 'raw' is confusing!  My guess is that, starting with ix+1, you wish to 
place mx+10, mx+20, ..., in ix+1, ix+2, etc., on to the end of s.  Is that it?

 s(ix+1:end) = mx+(10:10:10*(length(s)-ix))';

Roger Stafford