Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Problem in running my code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi Sir, kindly tell me where i am doing wrong??
TN=4;
n_vec=1:TN;
n=n_vec;
max=[0.32 0.51 0.112 1.3];
B=0.3;
Psi=0.6;
No=0.01;
tau=B./n;
for Max=max;
h=rand(1,TN);
Rhn=(tau*Psi*log(2))*(1+((max*h)/(tau*No)))
end
0 commentaires
Réponses (2)
KSSV
le 14 Fév 2019
Modifié(e) : KSSV
le 14 Fév 2019
TN=4;
n_vec=1:TN;
n=n_vec;
themax=[0.32 0.51 0.112 1.3];
B=0.3;
Psi=0.6;
No=0.01;
tau=B./n;
for Max=themax;
h=rand(1,TN);
Rhn=(tau*Psi*log(2)).*(1+((themax.*h)./(tau*No)))
end
Read about element by element array operations. When you multiply arrays element by element use .*.
Also note that, don't name the variables on the name of inbuilt functions......I have renames variable max with themax. There is inbuilt function to find maximum called max.
0 commentaires
madhan ravi
le 14 Fév 2019
Modifié(e) : madhan ravi
le 14 Fév 2019
Don't name variable max because there is an inbuilt function named max(), preallocate Rhn for speed and efficiency:
TN=4;
n_vec=1:TN;
n=n_vec;
Max=[0.32 0.51 0.112 1.3];
B=0.3;
Psi=0.6;
No=0.01;
tau=B./n;
Rhn=zeros(TN);
for k=1:TN
h=rand(1,TN);
Rhn(k,:)=(tau*Psi*log(2))*(1+((Max(k)*h)/(tau*No)));
end
Rhn
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!