Info

此问题已关闭。 请重新打开它进行编辑或回答。

Problem in running my code

2 次查看(过去 30 天)
Maheen Fazal
Maheen Fazal 2019-2-14
关闭: MATLAB Answer Bot 2021-8-20
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

回答(2 个)

KSSV
KSSV 2019-2-14
编辑:KSSV 2019-2-14
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.

madhan ravi
madhan ravi 2019-2-14
编辑:madhan ravi 2019-2-14
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

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by