From: "Ulrik Nash" <>
Newsgroups: comp.soft-sys.matlab
Subject: An even nastier vector operation!
Date: Thu, 18 Mar 2010 16:55:21 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <hntltp$r3r$>
Reply-To: "Ulrik Nash" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1268931321 27771 (18 Mar 2010 16:55:21 GMT)
NNTP-Posting-Date: Thu, 18 Mar 2010 16:55:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2106050
Xref: comp.soft-sys.matlab:617971

Hi Everyone,

In extension to a problem posted yesterday (Subject: Complicated vector operation!), I am having trouble with a perhaps even nastier version!

Suppose I have a horizontal vector, "A". For example:

A = [2 3 5 5 1 4]

Suppose also that I have a vertical vector of integers:

number_in_sample = [1 3 5]'

Now I wish to create a vertical vector, called "averages", which consists of averages of numbers drawn from A, where the number of elements drawn (without replacement), is defined by the vector number_in_sample.

So, the number of elements in "averages", is equal to the number of elements in "number_in_sample".

Can this be done without the need to loop?

I appreciate the help.