Improve efficiency of elseif loop
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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..
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!