Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Problem in running my code

1 回表示 (過去 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