コードのパフォーマンスの高速化
Afficher commentaires plus anciens
下記のようなプログラムを作成しましたが、実行が完了するのに時間がかかりすぎてしまいます。どのようにプログラムを修正したら、時間が短縮されますか? M5を求める式は正しいものとします。
k=deg2rad(62.5);
m=-log(2)/log(cos(k));
wx=10;
wy=10;
fov=25;
H=2.5;
i=1;
j=1;
sita=deg2rad(45);
z = 0;
eor = zeros(0,91);
esitax = zeros(0,7687177771);
esitay = zeros(0,7687177771);
ex = zeros(0,7687177771);
ey = zeros(0,7687177771);
M5 = zeros(0,91);
for oR=0:1:90
eor(i)=oR;
minMRC5=100000;
for sitax=0:pi/180:pi/2
for sitay=0:pi/180:pi/2
for x=0:0.1:wx
for y=0:0.1:wy
esitax(j)=sitax;
esitay(j)=sitay;
ex(j)=x;
ey(j)=y;
OR=deg2rad(oR);
R11=-sin(-sitay)*cos(OR-sitax);
R12=-sin(OR-sitax);
R13=cos(-sitay)*cos(OR-sitax);
H1=sqrt((wx/2-x)^2+y^2+(H-z)^2);
%h11
cost11=(H-z)/H1;%cos(ΦT)
t11=acos(cost11);%ΦT
rad2t11=rad2deg(t11);
cosr11=(R11*(wx/2-x)+R12*(-y)+R13*(H-z))/H1;%cos(ΦR)
r11=acos(cosr11);%ΦR
rad2r11=rad2deg(r11);%ラジアンを度に変換する
if abs(rad2r11)>fov
cosr11=10e-6;
end
h11=((cost11^m)*cosr11)/(power(H1,2));
H2=sqrt((wx-x)^2+(wy/2-y)^2+(H-z)^2);
cost21=(H-z)/H2;%cos(ΦT)
t21=acos(cost21);%ΦT
rad2t21=rad2deg(t21);
cosr21=(R11*(wx-x)+R12*(wy/2-y)+R13*(H-z))/H2;%cos(ΦR)
r21=acos(cosr21);%ΦR
rad2r21=rad2deg(r21);%ラジアンを度に変換する
if abs(rad2r21)>fov
cosr21=10e-6;
end
h21=((cost21^m)*cosr21)/(power(H2,2));
H3=sqrt((wx/2-x)^2+(wy-y)^2+(H-z)^2);
cost31=(H-z)/H3;%cos(ΦT)
t31=acos(cost31);%ΦT
rad2t31=rad2deg(t31);
cosr31=(R11*(wx/2-x)+R12*(wy-y)+R13*(H-z))/H3;%cos(ΦR)
r31=acos(cosr31);%ΦR
rad2r31=rad2deg(r31);%ラジアンを度に変換する
if abs(rad2r31)>fov
cosr31=10e-6;
end
h31=((cost31^m)*cosr31)/(power(H3,2));
H4=sqrt(x^2+(wy/2-y)^2+(H-z)^2);
cost41=(H-z)/H4;%cos(ΦT)
t41=acos(cost41);%ΦT
rad2t41=rad2deg(t41);
cosr41=(R11*(-x)+R12*(wy/2-y)+R13*(H-z))/H4;%cos(ΦR)
r41=acos(cosr41);%ΦR
rad2r41=rad2deg(r41);%ラジアンを度に変換する
if abs(rad2r41)>fov
cosr41=10e-6;
end
h41=((cost41^m)*cosr41)/(power(H4,2));
H15=(1/(H^2));
COST21=H/sqrt((wx/2)^2+(wy/2)^2+H^2);
COSR25=10e-6;
H25=((COST21)^m*COSR25)/(((wx/2)^2+(wy/2)^2+H^2));
COST31=H/sqrt(wy^2+H^2);
COSR35=10e-6;
H35=((COST31)^m*COSR35)/(wy^2+H^2);
H45=H25;
H5=(H15+H25+H35+H45)^2;
H111=h11+h21+h31+h41;
SNRMRC5 = 10*log10((H111^2)/H5);
if SNRMRC5<=minMRC5
minMRC5=SNRMRC5;
end
j=j+1;
end
end
end
end
M5(i)=minMRC5;
i=i+1;
end
plot(eor,M5,'Color',[0.1010, 0.7, 0.933],'LineWidth',2.5);
Réponse acceptée
Plus de réponses (2)
Jiro Doke
le 14 Août 2018
推測ですが、 zeros で事前割り当てをしてますが、大きさ0の変数を割り当ててますので効果が見れないのかもしれません。
eor = zeros(0,91);
ではなく
eor = zeros(1,91);
のように変更してみてください。
Atsushi Matsumoto
le 17 Août 2018
1 vote
5重のFor Loopがあって、それぞれ結構大きなループ回数なのでかなりの計算時間がかかりますね。  
ループ回数を減らすようにステップサイズを大きく取るわけには行きませんか?
例えば for sitay=0:pi/90:pi/2 といったように。
 
また、Forループをベクター化すると速くなるかもしれません。
1 commentaire
N/A
le 18 Août 2018
Catégories
En savoir plus sur プログラミング dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!