help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Anonymous functions as argument


From: Carnë Draug
Subject: Anonymous functions as argument
Date: Mon, 22 Mar 2010 22:32:37 -0400

Hi everyone

I think I'm having problems on getting anonymous functions working correctly. I've read the documentation a few times and googled but I can't see what I am doing wrong. Any help will be very appreciated.

I have a program that is suposed to fit a bunch of values with leasqr. The function that leasqr should use for fitting takes as argument some preprocess values. However, leasqr only accepts functions that have f(x,p) as it argument. My idea was to make an anonymous function with those as arguments and which would already have the preprocess inside. Here's my code

------------------------------------------------------------------------------------------------------------------
## Up to here is all the preprocess which I'm not copying to make it simple
## but if you think it may the problem just ask
preProcess{1} = nr/distance;
preProcess{2} = J1wxi;
preProcess{3} = alf2;
preProcess{4} = U;

#Df is the parameter to adjust
# func_PureDiffusion is in a .m file
func_PureDiffusion_for_leasqr = @(timestamps,Df) func_PureDiffusion(timestamps, Df, preProcess);

[f,p,kvg,iter,corp,covp,covr,stdresid,ci,r2]= leasqr (timestamps, IntValues, Df, @func_PureDiffusion_for_leasqr);
------------------------------------------------------------------------------------------------------------------

I don't think that this is the problem but here's the content of func_PureDiffusion.m

------------------------------------------------------------------------------------------------------------------
function frap = func_PureDiffusion (tList, Df, preProcess)
##  Assign parameters
RNrel    = preProcess{1};
J1wxi    = preProcess{2};
alf2    = preProcess{3};
U        = preProcess{4};

## Avoid assignment of physical irrelevant parameters by fitting routine
if (Df < 0 || Df > 800)
    frap = -100*ones(size(tList));
    return
end

## Time points have to be stored in a a row vector
if (size(tList,2)==1)
    tList = tList';
end
 
## Calculate the FRAP recovery curve
ea        = exp(-Df*alf2*tList);        # Exponential decay in Eq.(S.19)
frap    = 2*(RNrel)*(U.*J1wxi)'*ea;     # Eq.(S.22)
frap    = frap';                        # Transform to a column vector
------------------------------------------------------------------------------------------------------------------

And here's the error I get

------------------------------------------------------------------------------------------------------------------
error: error creating function handle "@func_PureDiffusion_for_regression"
error: evaluating argument list element number 4
error: evaluating argument list element number 1
error: called from:
## This is the line with the leasqr function
------------------------------------------------------------------------------------------------------------------

Thanks in advance for any help,
Carnë Draug

reply via email to

[Prev in Thread] Current Thread [Next in Thread]