MATLAB: How to fix this code to calculate the running average of the data without using toolbox methods such as movmean or smooth

averageMATLABrunning averagesmooth

The end goal is to smooth the data in a graph. What I have so far is in the first attachment and the .txt file is in the second. Thank you in advance for your help!

Best Answer

function avg = running_avg(signal, avg_window)
avg = zeros(1, length(signal);
for i = avg_window:length(signal)
avg(1, i) = sum( signal(i-avg_window+1:i) ) / avg_window;
end
end