Improve efficiency of elseif loop
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
LO
on 9 Jul 2021
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..
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!