Path: news.mathworks.com!not-for-mail From: "Ulrik Nash" <uwn@sam.sdu.dk> Newsgroups: comp.soft-sys.matlab Subject: Forming vector from another vector without looping Date: Wed, 17 Mar 2010 13:02:06 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 21 Message-ID: <hnqjse$8b1$1@fred.mathworks.com> Reply-To: "Ulrik Nash" <uwn@sam.sdu.dk> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1268830926 8545 172.30.248.37 (17 Mar 2010 13:02:06 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Wed, 17 Mar 2010 13:02:06 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2106050 Xref: news.mathworks.com comp.soft-sys.matlab:617535 Hi Everyone, Suppose I have a horisontal vector of numbers A, for example: A = [1 2 2 4 6 5] And I have a vertical vector B of whole numbers, where non of these numbers are greater than the number of elements in A. For example: B = [1 2 6]' Now I wish to create (without looping) a vertical vector of numbers where each number is derived as follows (in this example): C = [1 1+2 1+2+2+4+6+5]' Notice that B defines how many of the numbers in A are added (from left to right), to form each element in C. Can anyone tell me how to do this, without using loops? Regards, Ulrik.