How to calculate a running value of a function for every 30 samples?
Show older comments
clear all;
clc;
Nt= 2000; % Total samples
d = randn(1,Nt);
ratioCompute = sum(d)/mean(d);
I need calculate this ratioCompute for every 30 samples like a sliding window.
Answers (1)
Nt= 50; % Total samples
d = randn(1,Nt);
ratioCompute = movmean(d, 30)
4 Comments
Kalasagarreddi Kottakota
on 29 Nov 2022
Chunru
on 30 Nov 2022
will sum()/mean() = 30 for each window?
Kalasagarreddi Kottakota
on 30 Nov 2022
Edited: Kalasagarreddi Kottakota
on 30 Nov 2022
Chunru
on 1 Dec 2022
They you try:
ratioCompute = movsum(d, 30) ./ movmean(d, 30);
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!