1. I want to create a row in "Vector B" for each row in Vector A. The new row will hold the average of the positve values in the previous 50 rows of Vector A.
2. I also want to create Vector C to hold the standard deviation of the same previous 50 rows.
How can I do this without using a for loop? and will it be more efficient/faster?
% Does the first example in:
doc filter
% help you?
I'm not sure if/how i could use the filter function to help calc rolling standard deviation?
also, how would
1. i extract a rolling sum?
2. make a new column with each row based on the immediately previous row (e.g. equal to the row before it plus a random number).
% Download and try "moving standard deviation" form the MATLAB FEX at:
http://www.mathworks.com/matlabcentral/fileexchange/9428-moving-window-standard-deviation
>
> also, how would
> 1. i extract a rolling sum?
% Look at the source code in the above.
% It should give you a clue.
> 2. make a new column with each row based on the immediately previous row (e.g. equal to the row before it plus a random number).
% Is the desired first column just random numbers?
% If so, then my idea would be to create a matrix of random numbers
% (call it x) whose size has one more column than the original matrix.
% Then create another matrix such that:
b = [ 0 a]
% where a is the original matrix and 0 is a column of all zeros.
% then y = x + b should be your desired result.
-----------------------------------------------------------------------------
It prettymuch gives it to you right in the documentation, where it
says:
"Example
You can use filter to find a running average without using a for loop.
This example finds the running average of a 16-element vector, using a
window size of 5.
data = [1:0.2:4]';
windowSize = 5;
filter(ones(1,windowSize)/windowSize,1,data)
ans =
0.2000
0.4400
0.7200
1.0400
1.4000
1.6000
1.8000
2.0000
2.2000
2.4000
2.6000
2.8000
3.0000
3.2000
3.4000
3.6000"
Or have a look at this message:
<http://groups.google.se/group/comp.soft-sys.matlab/msg/e0d4e06cf8a703f0?hl=en>
that provides general advice on how to use filter to calculate various stats.
hth
Lars
anyone know how i might calculate rolling downside deviation?