Conditioned moving average window
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone, I'm a newbie to Matlab. I'm running a simulation and we're trying to analyse the moving average path length. As in the attached excel, the first column is the time elapsed and the second one is the path length. How do we plot an average moving window of 30 ticks, despite that some time ticks may have more than 1 path length? Thanks.
0 commentaires
Réponses (1)
Steven Lord
le 13 Juil 2017
If I understand your question correctly, I think you want to use the movmean function with the 'SamplePoints' option.
rng default
t = sort(rand(10, 1));
x = randi(10, 10, 1);
m = movmean(x, [0.25 0.125], 'SamplePoints', t);
results = table((1:10).', t, t-0.25, t+0.125, x, m, ...
'VariableNames', {'row', 't', 't_before', 't_after', 'x', 'movingAverage'})
As an example, consider row 3 of the results table. Row 3's movingAverage should consist of the mean of the values of x in all rows whose t values are between the values of t_before and t_after in row 3. For this sample code, I used rng default so you will receive the same t and x vectors as I did and thus I know that the first three rows contribute to row 3's movingAverage:
results{3, 'movingAverage'} - mean(x(1:3)) % should be 0
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!