Moving average of semi-deviation
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I am trying to calculate the moving average of the semi-deviation of 1 column of data. I have been able to find a semi-deviation add-in but cannot find anything about making a moving average of the semi-deviation.
Any help appreciated.
0 件のコメント
回答 (4 件)
Image Analyst
2016 年 6 月 15 日
What is the definition of " semi-deviation"?
If you mean "Standard Deviation" then try stdfilt() or movstd().
1 件のコメント
Image Analyst
2016 年 6 月 16 日
If you have a column vector of data and want the sd of data below the mean, just to
theMean = mean(data);
semiDeviation = std(data(data<theMean));
Star Strider
2016 年 6 月 16 日
I wrote my own function from your link and implemented an unfortunately inefficient filter to get the moving semideviation (using my own semideviation function):
semidev = @(x) sqrt(sum((mean(x(:)) - x(x(:) < mean(x(:)))).^2) / length(x(:)));
intvl = 10; % Index Interval For Moving Average
t = 1:100; % Time Vector
data = randn(1, 100); % Create Data
datav = [data, data(end-intvl+1:end)]; % ‘Pad’ ‘data’ With Repeat End Data
for k1 = 1:length(datav)-intvl;
wndw = k1:k1+intvl; % Subscript ‘Window’
sv(wndw) = semidev(datav(wndw)); % Calculate Semideviation Over ‘Window’
end
sv = sv(1:length(data)); % Trim To Correct Length
figure(1)
plot(t, data, 'bp')
hold on
plot(t, sv, '-r')
hold off
grid
It runs. I’ll let you determine if it produces the correct results.
0 件のコメント
N/A
2016 年 6 月 17 日
2 件のコメント
Star Strider
2016 年 6 月 17 日
If it gives you the result you want, go for it!
I based my anonymous function code on the expression you linked to. It should give you the result you want, since all the x-values meeting the criteria are set to their appropriate values, and those that do not meet the criteria are set to zero by default anyway.
Chris Turnes
2016 年 6 月 17 日
The movstd call here will include the zeros in the calculation. From the definition, it sounds like you want to ignore those points, rather than treat them as zero. I think you could do this by:
data_ds( data > data_movmean ) = nan;
data_movdsstd = movstd( data_ds, [intvl, 0], 'omitnan' );
This should actually ignore those points rather than just consider them to be zero.
参考
カテゴリ
Help Center および File Exchange で Data Preprocessing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!