Define anonymous function--
fnAggRF=@(n)(-1.3e-6.*(('CH4(n)'-'CH4(0'))/2)-8.2e-6*n+.043)*(sqrt(CH4(n)-sqrt(CH4(0))));
Then, simply
NB: You will have to have read the .mat file and have CH4 in memory when the function handle is created to build in the constants for CH4(0); if you have more than one file or CH4 array the function must be recreated with that new/updated array in memory at the time; otherwise the function will still reflect the original values; they are not dynamically updated if the variables upon which the anonymous function is dependent are changed. See the documentation for anonymous functions for more detail.
To avoid the above, you could always make the argument list to include the array...
fnAggRF=@(CH4,n)(-1.3e-6.*(('CH4(n)'-'CH4(0'))/2)-8.2e-6*n+.043)*(sqrt(CH4(n)-sqrt(CH4(0))));
By including CH4 in the argument list, it becomes a locally-scoped dummy argument in the expression and is not the same variable as that existing in the workspace or function space.
ERRATUM:
Matlab arrays are one-based; CH4(0) must be CH4(1), sorry...
fnAggRF=@(n)(-1.3e-6.*(('CH4(n)'-'CH4(1'))/2)-8.2e-6*n+.043)*(sqrt(CH4(n)-sqrt(CH4(1))));
Best Answer