필터 지우기
필터 지우기

Reduce processing time for the code

조회 수: 1 (최근 30일)
Santhosh Chandrasekar
Santhosh Chandrasekar 2018년 5월 28일
편집: Walter Roberson 2018년 5월 28일
Hi, the below-mentioned code takes a long time for processing. Can anyone help me to reduce the processing time? I think the for loop is the main reason for huge processing time. Is there nay another alternative to reduce the time.
tic
N=1;
V1=0.1;
V2=0.1;
V3=0.1;
V4=0.1;
V5=0.1;
C1=0.01;
C2=0.01;
C3=0.01;
C4=0.01;
C5=0.01;
S= [0 0 0 0 0;1 0 0 0 0;1 1 0 0 0;1 0 0 0 0;1 0 0 1 0];%star interdependency matrix
pA1 = 1;
UA = zeros(11,11,11,11,11,11,11,11,11,11);
for a1 = 0:0.1:N; %attacker’s set of actions on constituent system 1
pA2 = 1;
for a2 = 0:0.1:N; %attacker’s set of actions on constituent system 2
pA3 = 1;
for a3 = 0:0.1:N; %attacker’s set of actions on constituent system 3
pA4 = 1;
for a4 = 0:0.1:N; %attacker’s set of actions on constituent system 4
pA5 = 1;
for a5 = 0:0.1:N; %attacker’s set of actions on constituent system 5
A1 = [a1;a2;a3;a4;a5];
X11 = S * A1;
for i = 1:1:5
if X11(i) < 0
X11(i) = 0;
end
X1(i) = X11(i)/norm(X11);
end
% calculate inoperability
pd11 = 1;
for d1 = 0:0.1:N;
pd21 = 1;
for d2 = 0:0.1:N;
pd31 = 1;
for d3 = 0:0.1:N;
pd41 = 1;
for d4 = 0:0.1:N;
pd51 = 1;
for d5 = 0:0.1:N;
% defender’s set of actions effort on constituent systems respectively
UA(pA1,pA2,pA3,pA4,pA5,pd11,pd21,pd31,pd41,pd51) = (((X1(1))*(a1/(a1+d1))* V1)-C1*a1) + (((X1(2))*(a2/(a2+d2))* V2)-C2*a2) + (((X1(3))*(a3/(a3+d3))* V3)-C3*a3) + (((X1(4))*(a4/(a4+d4))* V4)-C4*a4) + (((X1(5))*(a5/(a5+d5))* V5)-C5*a5);
%Utility of Defender (U_A)
[maxm,indx] = max(UA(:));
[pA1m,pA2m,pA3m,pA4m,pA5m,pd11m,pd21m,pd31m,pd41m,pd51m] = ind2sub(size(UA),indx);
pA1m1 = 0.1 * (pA1m - 1);
pA2m1 = 0.1 * (pA2m - 1);
pA3m1 = 0.1 * (pA3m - 1);
pA4m1 = 0.1 * (pA4m - 1);
pA5m1 = 0.1 * (pA5m - 1);
pd1m1 = 0.1 * (pd11m - 1);
pd2m1 = 0.1 * (pd21m - 1);
pd3m1 = 0.1 * (pd31m - 1);
pd4m1 = 0.1 * (pd41m - 1);
pd5m1 = 0.1 * (pd51m - 1);
pd51 = pd51 + 1;
end
pd41 = pd41 + 1;
end
pd31 = pd31 + 1;
end
pd21 = pd21 + 1;
end
pd11 = pd11 + 1;
end
pA5 = pA5 + 1;
end
pA4 = pA4 + 1;
end
pA3 = pA3 + 1;
end
pA2 = pA2 + 1;
end
pA1 = pA1 + 1;
end
% define position numbers for a1, a2, a3, a4, a5, d1, d2, d3, d4, d5
UAmax = [maxm pA1m1 pA2m1 pA3m1 pA4m1 pA5m1 pd1m1 pd2m1 pd3m1 pd4m1 pd5m1] %output from max U_d
toc

답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by