I have a matrix (type:double) of size 106 x 103. The matrix represents European gridded temperature data for one timestep (a day).
For every day, I want to calculate the degree days (thermal time) for a species, based on the temperature recorded for each 'cell' (i,j element) in the matrix using a formula that I have coded in Matlab based on a sinewave approach.
So, ultimately, what I want to do is being able to apply a calculation to my matrix, that will provide individual output for each grid cell (i,j element) dependent on the temperature data that is recorded there. I could do this with a loop, but I have to accumulate these degree days for multiple years, so I would prefer to find a way of applying the calculation to each element in a daily matrix simultaneously (and then looping through the days (matrices)). From what I have read, you can use a cellfun if your matrix is a cell array (mine is not). Then I was also looking at the bsxfun option, but it seems like the functions are just standard functions..like mean, max etc. So now, I'm looking at using arrayfun in conjunction with a function I create from my algorithm to calculate degree days. I have been trying to write a test function but Matlab keeps throwing up the same error: I type:
function output=degreedays(x)
and Matlab throws back:
Error: Function definitions are not permitted in this context.
Can someone tell me what I'm doing wrong? Why is it not accepting the declaration of the function name?
function...
is function definition. It cannot happen everywhere and generally only happens at the top of the file containing said function. Once you have the function, you use it just likeoutStuff = degreedays(yourData);
– Zizy Archer