Thread Subject: Data Bin

Subject: Data Bin

From: AP Pal

Date: 4 Oct, 2009 15:51:01

Message: 1 of 3

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

Subject: Data Bin

From: the cyclist

Date: 8 Oct, 2009 18:45:19

Message: 2 of 3

"AP Pal" <avispal@gmail.com> wrote in message <haag95$o14$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.
>

You want to use the "filter" command. The first example in "doc filter" discusses how to do a running average. This can be adapted to your case.

You should double-check this, because I did it under the influence of rum, but I believe that if "x" is your original array, then

>> y = filter((1/10)*ones(1,10),1,x);

will give the running average of ANY ten consecutive entries, and

>> z = y(10:10:end);

will then give you the averages of the particular groups of ten that you want (i.e. every tenth row of "y").

Hope that helps.

the cyclist

Subject: Data Bin

From: Jan Simon

Date: 8 Oct, 2009 19:22:17

Message: 3 of 3

Dear AP Pal!

> 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.
> ...

You've asked exactly this question 2 days ago.
The answers have been exhaustive:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/262265

Kind regards, Jan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
double posting Jan Simon 8 Oct, 2009 15:24:21
rssFeed for this Thread

Contact us at files@mathworks.com