Can anybody help on this FOR loops

2 次查看(过去 30 天)
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 个评论
madhan ravi
madhan ravi 2020-6-5
Does all the variables return a scalar in each iteration?
Murad Nuri
Murad Nuri 2020-6-5
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...

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2020-6-5
[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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by