Calculation using if then in command window?

So I want to do a calculation if a specific incident takes place. Below is the first attempt. SumOrgNO3_tot is calculated from OrgNO3_tot as a single wave. JDay is the time in number form since New Years Eve 2012/2013. Sunrise in Alabama is 6 am and sunset at 8 PM (ish). I'm stacking each data point (so sumOrgNO3_tot[3] = OrgNO3_tot[0]+OrgNO3_tot[1]+OrgNO3_tot[2]+OrgNO3_tot[3] and sumOrgNO3_tot[4] = OrgNO3_tot[0]+OrgNO3_tot[2]+OrgNO3_tot[3]+OrgNO3_tot[4] etc....)

SumOrgno3_tot= (soasjday-floor(soasjday))>0.24999999999 && (soasjday-floor(soasjday))<0.83333333333 ? Sumorgno3_tot[p,6479]-sumorgno3_tot[p-1] : SumOrgno3_tot

So basically it says that if the sun is up (fraction of day = 0.25-0.84), then I want the last reported number before then (p-1) subtracted from the rest of the wave. This helps me to say when night starts, then sumorgno3_tot starts from 0 again.

I want to do this for a wave covering 45 days rather than go through 45 times and subtracting the p-1. S for instance, below is some sample data. When jday > 0.25 then orgno3_tot = 0. I then want sumorgno3_tot at that point to be sumorgno3_tot - 0.0302465

Does this make sense?

Sample data

OrgNO3_tot sumOrgNO3_tot SOASJDay
0.00094628 0.0279438 154.229
0.00108462 0.0290284 154.236
0.00121807 0.0302465 154.243
0 0.0302465 154.25
0 0.0302465 154.257
0 0.0302465 154.264
0 0.0302465 154.271
0 0.0302465 154.278

chemgoof wrote:
...
Does this make sense?
...


Not really ??? I can not seem to be able to read past the wave names to understand what is happening mathematically. Can you boil this down to a math problem with waves wA, wB, wC, ... or something equivalent and easier to start. Also, I do not see where 45 waves come to play here. Finally, are you missing an index of p on soasjday in the conditional test (or is soasjday a variable value not a wave)?

I might recommend to do this also to help readability and stick with the bounds you want to use ...

variable vfloor = floor(wjday), endp = 6479
wSum_tot = ((wjday[p] - vfloor) <= 0.25) || ((wjday[p] - vfloor) >= 0.84) ? wSum_tot[p] : wSum_tot[p,endp] - wSum_tot[p-1]


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
It was for 45 days, not waves. I think I just figured it out though. I tried SumOrgNO3_Tot=(soasjday-floor(soasjday))>0.24999999999 && (soasjday-floor(soasjday))<0.83333333333 ? 0 : (sumorgno3_tot[p-1]+OrgNO3_tot[p]). There are actually about 20 decimal places in the numbers so the addition below doesn't add up perfectly, but it works in the program.

So if we rename the waves Wa Wb Wc, then when Wc-floor(Wc)>0.25 and Wc-floor(Wc)<0.833333333, then Wb=0, otherwise, Wb=Wb[p-1]+Wa[p] so the 2nd column starts at 0 til each nightfall then it starts adding up the Wa values. I want a lump sum (Wb) of the nighttime values of the Wa.

In the example above (see data below), when Wa = 0 is when Wc falls in the >=0.25 and <=0.8333333. So 0.0279438 then 0.0279438+0.00108462=0.0290284 (Wb[p-1]-Wa[p]=Wb[p]) then 0.0290284+0.00121807=0.0302465 then the sun comes up so 0.0302465-0.0302465=0. This takes place til the end of the 45 day series.

As a side note, we did this study in Centerville, AL! Hot and humid created some interesting problems with our instruments. (Saw you were at Huntsville)

Thanks for the help.

Wa Wb Wc
0.00094628 0.0279438 154.229
0.00108462 0.0290284 154.236
0.00121807 0.0302465 154.243
0.00000000 0.0302465 154.25
0.00000000 0.0302465 154.257
0.00000000 0.0302465 154.264
0.00000000 0.0302465 154.271
0.00000000 0.0302465 154.278

I am still not sure where you get Wa to be a number or zero. It seems, if you already have this, you could just as easily write ...

Wb[1,npnts(Wb)-1] = Wb[p-1] + Wa[p]


Also, I wonder how your code handles the starting point of the waves. I am surprised you do not get an exception for wave out of range when you try to do the Wb[p-1] at point p = 0. Unless you are starting at daylight so the first starting points are all zero and never get considered???

I suggest again that you might want to use the OR test rather than the AND logic.

(value >= min) || (value <= max)


Then, you are staying true to the cutoffs (0.25 and 0.84) rather than approximating them.

Also, since Wc has a known floor, why not just subtract it out up front and test the result?? The code would run faster and be a bit clearer to read.

duplicate/FREE Wc Wsc
Wsc = Wc - floor(Wc)
Wb = ((Wsc >= 0.25) || (Wsc <= 0.84)) ? TRUE : FALSE


As for the hot summer days in Centerville ... I wonder what happened to your instruments over the last week during the state freeze. :-)

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville