one reason to dislike Matlab
Nov. 11th, 2008 10:05 pmArray indices start from 1, which means that to properly avoid fencepost errors, your code ends up looking like this:
Lots of extraneous 1s. (And that's because the data is nice: this code can't handle partial days)
I hear NumPy is a very good substitute.
for day=1:floor(size(p1,2)/24) %for each day
daytotal(day) = sum(p(24*(day-1)+1:24*(day-1)+24));
endLots of extraneous 1s. (And that's because the data is nice: this code can't handle partial days)
I hear NumPy is a very good substitute.
(no subject)
Date: 2008-11-12 06:34 am (UTC)(no subject)
Date: 2008-11-12 06:39 am (UTC)(no subject)
Date: 2008-11-12 06:53 am (UTC)(no subject)
Date: 2008-11-12 07:18 am (UTC)(no subject)
Date: 2008-11-12 12:37 pm (UTC)= 24 * (day - 1) + 24 + 1:24 * (day-1)
= 24 * (day - 1 + 1) + 1:24 * (day - 1)
= 24 * day + 1:24 * (day - 1)
This dividing by 24 to get your days just to multiply by 24 later is rubbing me the wrong way as well.
Is p different from p1?
You could do something like this, but I am not sure this is any better.
It does eliminate the -1.
for hour = 1:(size(p1,2))
daytotal(floor(hour/24)) = sum(p(hour) + 0:1/24:(1-1/24)*hour);
end
(no subject)
Date: 2008-11-12 03:38 pm (UTC){a, b, c}[[1]] evaluates to a
{a, b, c}[[1]] evaluates to List, because {a, b, c} is actually List[a,b,c]
The result of this means that you can do such strange things as anonymous recursive functions, for example (If[#>1,# #0[#-1],1])& is the factorial function.
(no subject)
Date: 2008-11-12 03:39 pm (UTC){a, b, c}[[0]] evaluates to List, because {a, b, c} is actually List[a,b,c]
(no subject)
Date: 2008-11-12 06:01 pm (UTC)(no subject)
Date: 2008-11-12 06:23 pm (UTC)