필터 지우기
필터 지우기

Leaping loop with constant rows for each identity

조회 수: 2 (최근 30일)
wesso Dadoyan
wesso Dadoyan 2016년 10월 6일
답변: Andrei Bobrov 2016년 10월 6일
I have a vector where the first 80 rows belong to a company, the 2nd 80 to another company ... last 80 rows belong to company N I want a rolling average of the last 12 rows for all rows starting row 12. so for row 12, i want the average of rows 1 till 12, for row 13 i want the average of rows 2 till 13 ....for row 80 the average of rows 69 till 80. but for row 81 till 91 it should be empty since i don't have 12 observations that proceeds these rows.then it starts again row 92 is the average of rows 81 till 92 etc.... How can I design this till i reach the end of the vector? i tried
for i=12:80:N
A(i)=B(i:i-11,1);
end
but it doesn't work properly. Any hint will be greatly appreciated

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 10월 6일
A - your array (n x 1)
out = conv2(A,ones(12,1)/12,'valid');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by