Path: news.mathworks.com!not-for-mail
From: "Andrew Stevens" <astevens@JUNKusgs.gov>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Data Bin
Date: Sun, 4 Oct 2009 17:05:03 +0000 (UTC)
Organization: US Geological Survey
Lines: 44
Message-ID: <haakjv$6r1$1@fred.mathworks.com>
References: <haafq5$mvs$1@fred.mathworks.com>
Reply-To: "Andrew Stevens" <astevens@JUNKusgs.gov>
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 1254675903 7009 172.30.248.35 (4 Oct 2009 17:05:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 4 Oct 2009 17:05:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 592751
Xref: news.mathworks.com comp.soft-sys.matlab:574844


"AP Pal" <avispal@gmail.com> wrote in message <haafq5$mvs$1@fred.mathworks.com>...
> I am new to matlab and am stuck  with what seems simple task
> i have  a column of data 1000 pts long. i need to average in groups of 10 so i need to generate a new matrix which has 100pts.
> 
> i was trying to write a code with a mini file and keep making mistakes
> 
> p=X
> n=1;
> i=1;
> m=length(X);
> 
> avg_pts= 2;
> z= length(X)/avg_pts
> % q=0;
> p(1,1)=X(1,1);
> 
>   for i=(1:1:z);
>      
>        for q=(1:1:avg_pts);
>            if n+q<=m
>        p(q,1)=p(q,1)+X(n+q,1);
>            else
>            end
>        end
>        y(i,1)=p(q,1)/avg_pts;
>       n=n+avg_pts;
>       
>   end
>  
> 
> Any help will be greatly appreciated
> thanks

Hi,

You many want to try something like:

%generate a dataset
y=rand(1000,1);

%average in 10 point bins
ym=mean(reshape(y,10,100));

-Andrew