Hi i want to do moving average in s-function level 2, When using matlab script i wrote this formula where r=residual with size 1, samples is the time step.
if samples > window
sumS = 0;
for l = 1:window,
S = (1/window) * (Htime(samples,:)) ./ R.^(1/2);
S= (1/window) * sum( (Htime(samples-(l-1):samples,:)) ./ R.^(1/2) );
sumS=sumS + S*S';
CovEnsemble=S*Pold*S' + (1/window);
CovDifference = CovTime - CovEnsemble;
if CovDifference > 0
Qparameter = CovDifference / sumS;
Qparameter = 0;
the problem is when i am using s-function level 2, where i want to get this residual ~ r(:,samples-window+1:samples) , where i only have 1 data only when running the simulation. how do i get the previous data (residual) in s-function and to use in concurrently?
How do i define/ do it in s-function level 2? Thank you.