Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Create a new vector from a current vector
Date: Mon, 5 Nov 2007 15:26:40 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 32
Message-ID: <fgncng$l6b$1@fred.mathworks.com>
References: <fgnbec$21u$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1194276400 21707 172.30.248.38 (5 Nov 2007 15:26:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 5 Nov 2007 15:26:40 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:436101



"Amir Safari" <amsa36060@yahoo.com> wrote in message <fgnbec$21u
$1@fred.mathworks.com>...
> 
> Hi MATLAB users,
> 
> Suppose we have a matrix or vector with only one column of 
> length 20.
> 
> A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];
> 
> My question is that how to create a new matrix or vector 
> from A so that the new vector be sums of every 4 values of 
> A. Therefore the new vector of B will have a length of 5.
> 
> B=[11,14,14,17,10];
> 
> How to create B from A?
> 
> Thank you very much.
> Amir

Easy enough.

A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];

C = repmat({ones(4,1)},1,5);
A*blkdiag(C{:})

ans =
    11    14    14    17    10

John