Can anybody help on this FOR loops

1 view (last 30 days)
I do not really understand what exactly is wrong here.
I want to have the following variables give seperate results for each n.
Can you help me correct this?
for n = 1:N
Ln(n)=V(1:N,n)'*M*l
Mn(n)=V(1:N,n)'*M*V(1:N,n)
Gamma_n(n)=Ln/Mn
Mn_star(n)=Ln^2/Mn
fn_st(n)=Gamma_n.*M*V(1:N,n)
end
  2 Comments
madhan ravi
madhan ravi on 5 Jun 2020
Does all the variables return a scalar in each iteration?
Murad Nuri
Murad Nuri on 5 Jun 2020
It does. But after each step of n, the previous value for the variable vanishes, this is not i want to have. I want for n=1 to have Ln(1), etc, for n=2 Ln(2), etc...

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 5 Jun 2020
[Ln, Mn, Gamma_n, Mn_star, fn_st] = zeros(N,1);
for n = 1:N
Ln(n)=V(1:N,n)'*M*l;
Mn(n)=V(1:N,n)'*M*V(1:N,n);
Gamma_n(n)=Ln(n)/Mn;
Mn_star(n)=Ln(n)^2/Mn;
fn_st(n)=Gamma_n(n).*M*V(1:N,n);
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!