If else condition for the rainfall

I have series of daily rainfall data, computed curve number (CN). To compute runoff, I need to fulfill these two conditions
if Rainfall > 0.2
then Runoff = 1000/CN -10
else
Runoff =( Rainfall -0.2 * (1000/CN -10)^2)/Rainfall + 0.8 *(1000/CN -10)
Could any body suggest code for this? I tried to use following script
Runoff = ones(size(Rainfallinches));
>> idx = Rainfallinches >0.2;
>> Runoff(idx)= (1000* 1/Curvenumber -10);
but this doesnot work Kind regards, Saleem
[EDITED, Jan, copied from a new thread:]
My data is as follow Rainfall CN 8 65 2 66 6 88 8 73 5 63 4 65 6 66 5 88 1 73 2 63 3 65 5 66 1 88 5 73 10 63 4 65 3 66 3 88 4 73 3 63 I want to compute Runoff for the following conditions if Rainfall >10 then Runoff = 1000/CN-10 otherwise Runoff = (Rainfall - 0.2 * (1000/CN -10)^2)/Rainfall + 0.8 *(1000/CN -10) Please suggest me code for that kind of data.

댓글 수: 3

Jan
Jan 2015년 10월 1일
편집: Jan 2015년 10월 1일
I've formatted your code. Please explain "it does not work" with any details. It is less efficient to guess the problem, when you see it on your screen already.
Please post input data for your code e.g. created by rand, such that we can see the type and the dimensions.
Jan
Jan 2015년 10월 1일
편집: Jan 2015년 10월 1일
Please do not open a new thread to provide data for an open question. This is too confusing for the readers.
If you post values, please use a form, which can be inserted in Matlab's command window by copy&paste. Only then it is clear to the readers. What are the size and type of the variables Rainfallinches and Curvenumber? And again: Please explain what "it does not work" mean. Give us a chance to help you.
Eng. Fredius Magige
Eng. Fredius Magige 2015년 10월 1일
Tell us all coefficient as Q=kiA

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

답변 (1개)

Thorsten
Thorsten 2015년 10월 1일
편집: Thorsten 2015년 10월 1일

0 개 추천

You didn't mention what went wrong; the following code should work for you:
Rainfall = rand(1,10); % fake some data
CN = 23; % assume it is a scalar, fake some value
idx = Rainfall > 0.2;
Runoff(idx) = 1000/CN - 10;
Runoff(~idx) = (Rainfall - 0.2 * (1000/CN -10)^2)/Rainfall + 0.8 *(1000/CN -10);

댓글 수: 2

Saleem Sarwar
Saleem Sarwar 2015년 10월 1일
Thanks Thorsten for your reply. There seem to be some error in this code. My data is as follow Rainfall CN 8 65 2 66 6 88 8 73 5 63 4 65 6 66 5 88 1 73 2 63 3 65 5 66 1 88 5 73 10 63 4 65 3 66 3 88 4 73 3 63 I want to compute Runoff for the following conditions if Rainfall >10 then Runoff = 1000/CN-10 otherwise Runoff = (Rainfall - 0.2 * (1000/CN -10)^2)/Rainfall + 0.8 *(1000/CN -10) Please suggest me code for that kind of data.
Kind regards, Saleem
Runoff(~idx) = (Rainfall(~idx) - 0.2 * (1000/CN -10)^2)./Rainfall(~idx) + 0.8 *(1000/CN -10);

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

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 10월 1일

댓글:

2015년 10월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by