Improve efficiency of elseif loop

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by