Difficulty Coming up with a solution, would there be a convenient command for this ??
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Putsandcalls
el 17 de En. de 2016
Editada: Putsandcalls
el 17 de En. de 2016
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 comentarios
Respuesta aceptada
Triveni
el 17 de En. de 2016
Editada: Triveni
el 17 de En. de 2016
I don't know what is your "m1". As i understand. following should be help you
Matrix = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10];
X = 0.94;
Matrix1 = [5; 6 ; 7 ; 8 ; 9 ;10 ;0 ;0 ;0 ; 0];
Matrix2 = [4; 6 ; 7; 1; 0 ; 0; 0 ; 0 ; 0 ; 0];
Matrix3 = [1; 2 ; 3; 0; 0 ; 0; 0 ; 0 ; 0 ; 0];
Z = [Matrix Matrix1 Matrix2 Matrix3];
out = zeros(1,1,10);
m1=Matrix1; % I have taken m1=Matrix1
out(:,:,1) = (1-X)*((X.^1)*(Matrix(1,1)-m1(1,1)).^2);
for k=2:10
out(:,:,k) = out((k-1)) + (1-X)*((X.^k+1)*(Matrix(k,1)-m1(k,1)).^2)
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!