Clear Filters
Clear Filters

Need help finding a moving average

4 views (last 30 days)
I'm trying to determine the moving average of a file with several columns. Each column is a separate data set and I want to find a moving average of each data set. I can't seem to figure out how to deal with each column by itself, so I basically append each data set ontop of each other and make a very large single string of values, and deal with it that way. I nkow this isn't the best way to do this, but that's what my code does now. Once that's done (which my code successfully does), I want to extract the values from this large string and rearrange it into columns again. I'm having trouble doing code is as follows
function [absorbance_MA] = co2_quantify(wave_number, absorbance_co2blcorr);
numFiles = 5;
n = 100; %defines period of moving average
for i = n:numFiles*length(absorbance_co2blcorr)-n
absorbance_MA_bl(i) = mean(absorbance_co2blcorr(i:i+n));
for i = 0:numFiles-1
absorbance_MA(:,i+1) = absorbance_MA_bl(length(absorbance_co2blcorr)*i+1:length(absorbance_co2blcorr)*(i+1)-n)';
Any help is appreciated. I've attached the relevant files needed to run the code.

Accepted Answer

Rick Rosson
Rick Rosson on 7 Mar 2016
n = 100;
b = ones(1,n)/n;
a = 1;
absorbance_MA = filter(b,a,absorbance_co2blcorr);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!