Difficulty Coming up with a solution, would there be a convenient command for this ??
古いコメントを表示
I am looking to implement a for loop but am not quite sure of how to do this given the for loop. I have thought really hard and it may either be due to a lack of skills but am unable to find an answer. Suppose I have a matrix and some predefined variable:
Matrix = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
X = 0.94
What I would like is for matlab to do the following: First construct running mean as follows:
m = zeros(10,1)
for n = 1: m(1,1) = (1-0.94)*(0.94)*(1) = 0.0564
for n = 2: m(2,1) = (1-0.94)*(0.94.^2)*(1) + (1-0.94)*(0.94.^1)(2) = 0.053016
for n = 3: m(3,1) = (1-0.94)*(0.94.^3)*(1) + (1-0.94)*(0.94.^2)(2) + (1-0.94)*(0.94.^1)(3)
for n = 4: m(4,1) = (1-0.94)*(0.94.^4)*(1) + (1-0.94)*(0.94.^3)*(2) + (1-0.94)*(0.94.^2)*(3)+(1-0.94)*(0.94.^1)*(4)
m1 = [0.0564; 0.053016; ... ] %%this is my output matrix
To be precise, I am looking to calculate something similar to the formula where d is equal to X set as 0.94. The calculation above describes the process for calculating the mean but if I get the intuition behind executing it, I can perform it for the variance.
Matrix = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10];
X = 0.94;
r = zeros(10);
for t = 1:10
r(t,1) = Matrix(t,1);
for i = 1:10
m(i,1) = (1-X)*(X.^i)*r(t,1);
end
end
This is a code that I came up with but clearly, it is very wrong and I have also tried to index it from t = 10:-1:1, which is also wrong. I have been stuck on this for a very long time and it would be great if someone can help me.
Any help is much appreciated. Thank you
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!