Improve efficiency of elseif loop

1 visualización (últimos 30 días)
Patrick Lonergan
Patrick Lonergan el 9 de Jul. de 2021
Comentada: Patrick Lonergan el 9 de Jul. de 2021
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

Respuesta aceptada

LO
LO el 9 de Jul. de 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..
  1 comentario
Patrick Lonergan
Patrick Lonergan el 9 de Jul. de 2021
Thanks, works a treat, appreciate the help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by