Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Problem in running my code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
KSSV
am 14 Feb. 2019
Bearbeitet: KSSV
am 14 Feb. 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 Kommentare
madhan ravi
am 14 Feb. 2019
Bearbeitet: madhan ravi
am 14 Feb. 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 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!