How to calculate moving standard deviation in a matrix?

Hi Guys, I have got a matrix :378x9. I need to calculate the moving standard deviation with a window size of 180(starting from row one). Can somebody help me please?

답변 (1개)

Manolis Michailidis
Manolis Michailidis 2015년 10월 13일

0 개 추천

댓글 수: 7

I tried to use it, but it tells me there are some errors
Manolis Michailidis
Manolis Michailidis 2015년 10월 13일
편집: Manolis Michailidis 2015년 10월 13일
what errors do you get discribe them please and write your code
Here i made a try and it works fine
X= [randi(10,1000,1) randi(100,1000,1)]; %create random matrix wit 2 columns
for kk=1:size(X,2)
s(:,kk)=movingstd(X(:,kk),180,'f');
end
also consider in mind that in this example i compute the moving std per column , also you can make it work for each row. Just replace size(X,2) with size(X,1) and s(:,kk) , X(:,kk) with s(kk,:), X(kk,:) .
thank you very much. I tried but i have some problem defining movingstd; i try with the code: std = sqrt((sum(x.^2) - n*xbar.^2)/(n-1)) . But 2 problems arise: the first is this answer:Undefined function or variable 'n'.After this I try with : Trial>> std = sqrt((sum(countries.^2) - N*bar.^2)/(N-1)) (as suggested by the command window), but it appears:Error using bar (line 42). I do not know what to do. Please,do you have any idea? Thank you Andrea
Manolis Michailidis
Manolis Michailidis 2015년 10월 13일
편집: Manolis Michailidis 2015년 10월 13일
You don't have to type all this in command window, look at the function syntax , first variable is you matrix (lets say X) , next is moving window length (180) and finally optional parameter is 'f' forward. You have already the function why don't you call it?
I tried but i failed again. I change the question: do you know how to calculate the standard deviation of the matrix of each column till row 180?I think I ll do it per 199 times so
for kk=1:size(X,2) % kk is your column index
s(1:180,kk)=movingstd(X(1:180,kk),180,'f');
end

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 10월 13일

편집:

2015년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by