MATLAB Answers

Improve efficiency of elseif loop

조회 수: 3(최근 30일)
Patrick Lonergan
Patrick Lonergan 2021년 7월 9일
댓글: Patrick Lonergan 2021년 7월 9일
UpperTempEst=[],
for i=1:11307211
if Power(i,1) < 360
TempUpper=prctile(T0,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>360 && Power(i,1)<720
TempUpper=prctile(T10,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>720 && Power(i,1)<1080
TempUpper=prctile(T20,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>1080 && Power(i,1)<1440
TempUpper=prctile(T30,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>1440 && Power(i,1)<1800
TempUpper=prctile(T40,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>1800 && Power(i,1)<2160
TempUpper=prctile(T50,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>2160 && Power(i,1)<2520
TempUpper=prctile(T60,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>2520 && Power(i,1)<2880
TempUpper=prctile(T70,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>2880 && Power(i,1)<3240
TempUpper=prctile(T80,95)
UpperTempEst=[UpperTempEst;i TempUpper]
elseif Power(i,1)>3240 && Power(i,1)<3600
TempUpper=prctile(T90,95)
UpperTempEst=[UpperTempEst;i TempUpper]
end
end
I have the above code that relates a power generation to an upper temperature estimate. The power is 1 collumn and 11307211 rows.
I previously split the historic data into ten power bins and have removed outliers from each set. The T-- refers to the temperatures given for each set, and as you can see I am setting the upper limit of the temperature as the 95 percentile.
This manner is just far too computational intesive and I was wondering if anyone has a method that would be much more efficient.
Thanks

채택된 답변

LO
LO 2021년 7월 9일
You don't need the loops, you can use logical indexes. This will speed up the process.If your Power array has 1 dimension you can remove the (:,1).
example:
Power(Power (:,1) < 360) = prctile(T0,95);
Power(Power(:,1)>360 & Power(:,1)<720) = prctile(T10,95);
% etc..
  댓글 수: 1
Patrick Lonergan
Patrick Lonergan 2021년 7월 9일
Thanks, works a treat, appreciate the help

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by