How to calculate a running value of a function for every 30 samples?

조회 수: 2 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2022년 11월 29일
댓글: Chunru 2022년 12월 1일
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.

답변 (1개)

Chunru
Chunru 2022년 11월 29일
Nt= 50; % Total samples
d = randn(1,Nt);
ratioCompute = movmean(d, 30)
ratioCompute = 1×50
-0.1405 -0.1198 -0.1145 -0.0710 0.0116 0.0064 0.0398 0.0308 0.0168 0.0260 0.0339 0.0456 0.0118 0.0280 0.0412 0.0195 0.0005 0.0667 0.0811 0.0800 0.0896 0.1074 0.1868 0.1181 0.0611 0.1342 0.2335 0.2915 0.2876 0.2794
  댓글 수: 4
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2022년 11월 30일
편집: Kalasagarreddi Kottakota 2022년 11월 30일
yes, here I was making a simple formulation. But actual formula which I will compute is different. Just am I looking to find a way to compute a ratio for every 30 samples.
Chunru
Chunru 2022년 12월 1일
They you try:
ratioCompute = movsum(d, 30) ./ movmean(d, 30);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by