How do i calculate for conditions

2 visualizaciones (últimos 30 días)
Rahah Hadri
Rahah Hadri el 3 de Mzo. de 2021
Comentada: Rahah Hadri el 30 de Mzo. de 2021
Hi,
I am trying to calculate actual evapotranspiration(AE) from my data. the conditions and calculation are as follows:
if P - PET > 0
AE = PET
elseif P - PET < 0
AE = P - SMdiff
P, PET and SMdiff are all 12 x 1 double.
How do i compute this in matlab?

Respuesta aceptada

Drishan Poovaya
Drishan Poovaya el 25 de Mzo. de 2021
I understand that you want code to calculate these conditions. I assume you are looking for a vectorized approach rather than a for loop. The code below should perform your calculations
AE = P>PET %logical 12 x 1 array
AE = AE.*PET + (~AE).*(P-SMdiff)
  1 comentario
Rahah Hadri
Rahah Hadri el 30 de Mzo. de 2021
Thank you so much! This did exactly what I wanted.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by