How do i calculate for conditions

조회 수: 2 (최근 30일)
Rahah Hadri
Rahah Hadri 2021년 3월 3일
댓글: Rahah Hadri 2021년 3월 30일
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?

채택된 답변

Drishan Poovaya
Drishan Poovaya 2021년 3월 25일
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
Rahah Hadri
Rahah Hadri 2021년 3월 30일
Thank you so much! This did exactly what I wanted.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by