Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:07:50+00:00 2026-05-16T04:07:50+00:00

Computing a running average of a simple 1-D data vector seems simple enough. Indeed,

  • 0

Computing a running average of a simple 1-D data vector seems simple enough. Indeed, the MATLAB documentation for FILTER happily claims something like:

You can use filter to find a running average without
using a for loop. This example finds the running average
of a 16-element vector, using a window size of 3:

D = [1:0.2:4]';
windowSize = 3;
F = ones(1,windowSize)/windowSize;
Df = filter(F,1,D);

The result:

Image of raw and filtered data plot from above example http://www.tc.umn.edu/~vande642/pictures/untitled.png

For my purposes, there are two annoying things about this result: output point n is the average of input points n-(windowSize-1)..n (i.e. not centered, as evidenced by the horizontal shift) and points to the left of the available data are treated as zeros.

FILTFILT deals with both issues, but has other drawbacks. It’s part of the Signal Processing Toolbox, and it doesn’t deal well with NaNs (which I’d like excluded from the mean).

Some people on FEX obviously had the same frustrations, but it seems odd to me that something this simple requires custom code. Anything I’m missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:07:51+00:00Added an answer on May 16, 2026 at 4:07 am

    You can also do a running average using convolution. Thus, you don’t need to worry about filtfilt.

    For example, you could use

    D = [1:0.2:4];
    windowSize = 3;
    F = ones(1,windowSize)/windowSize;
    Df = conv(D,F);
    %# if you didn't use 'valid', Df is larger than D. To correct:
    halfSize = floor(windowSize/2);
    Df = Df(halfSize+1:end-halfSize);
    

    Of course, you’d still have to deal with the edge, so you should pad D first, or run conv with the ‘valid’ argument. For example, you could use PADARRAY if you have the image processing toolbox.

    The simplest way to pad would be to replicate the first and last values. If you know more about your data, other approaches can turn out to be more suited.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 504k
  • Answers 504k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That's not a valid JSON-String (check jsonlint.com) There are unescaped… May 16, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer var result = outer.SelectMany((inner, index) => inner.Select(item => Tuple.Create(item, index))); May 16, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer This is easily solved by adding the time you want… May 16, 2026 at 3:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Eclipse Helios periodically starts running a job which displays Computing additional info. During this
My project when it is running, will collect a large number of string text
So I'm a little confused by this terminology. Everyone refers to Asynchronous computing as
Cloud computing is about providing computing, storage and networking capacities on demand. It is
I'm looking for a framework (open source) for distributed computing for .Net / Mono
I can call FFmpeg with subprocess.Popen and retrieve the data I need, as it
Is this code snippet poorly designed? Originally, there was only one AppDomain.Unload , in
Does anyone know of a better GUI client for displaying Windows System Monitor log
First off, I'm programming a game. Currently in the render function there are two
Disclaimer: My posts are apparently always verbose. If you happen to know the answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.