Filter löschen
Filter löschen

Can anybody help on this FOR loops

2 Ansichten (letzte 30 Tage)
Murad Nuri
Murad Nuri am 5 Jun. 2020
Beantwortet: madhan ravi am 5 Jun. 2020
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 Kommentare
madhan ravi
madhan ravi am 5 Jun. 2020
Does all the variables return a scalar in each iteration?
Murad Nuri
Murad Nuri am 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...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by