Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
nlinfit with anonymous function

Subject: nlinfit with anonymous function

From: Mateusz Gos

Date: 10 Mar, 2009 14:55:16

Message: 1 of 4

Hi,

I suppose I've got a simple question for someone who's already used to the new syntax for passing variables via anonymous function: Why does the command below not work?

a = nlinfit(x,y,@(a0) myfun(a0,x,constants),a0);

a0 is the initial guess of a, x is set of independent variables, y - set of dependent ones, constants is cell array of constant arrays/variables.

the error I get is 'Too many input arguments.'

I will greatly appreciate your help,
Mateusz

Subject: nlinfit with anonymous function

From: John D'Errico

Date: 10 Mar, 2009 15:14:02

Message: 2 of 4

"Mateusz Gos" <webmaster24@wp.pl> wrote in message <gp5v0k$dtu$1@fred.mathworks.com>...
> Hi,
>
> I suppose I've got a simple question for someone who's already used to the new syntax for passing variables via anonymous function: Why does the command below not work?
>
> a = nlinfit(x,y,@(a0) myfun(a0,x,constants),a0);
>
> a0 is the initial guess of a, x is set of independent variables, y - set of dependent ones, constants is cell array of constant arrays/variables.
>
> the error I get is 'Too many input arguments.'
>
> I will greatly appreciate your help,
> Mateusz

Well, since you have not told us the entire error
message, or what is myfun, this is just a guess.
The answer is probably either:

1. You have defined myfun improperly for this
sequence of arguments.

2. You have defined a function or script called
nlinfit. When matlab tries to call the built-in
nlinfit, it sees your function instead. Do not
name your functions with pre-existing names.

I cannot tell which it is from your sparse
description of the error.

John

Subject: nlinfit with anonymous function

From: Priya Moorthy

Date: 10 Mar, 2009 15:24:36

Message: 3 of 4

Hi,

The model function that you pass in to nlinfit has to accept two arguments,
since nlinfit calls the function with two arguments-- the vector of
coefficients (a) and the vector of independent values (x).

From the help for nlinfit:

"MODELFUN is a function, specified using @, that accepts two arguments, a
coefficient vector and the array X, and returns a vector of fitted Y
values."

Thus, you will have to construct your anonymous function to take in x and a:

a = nlinfit(x,y,@(a0, x) myfun(a0, constants),a0);

HTH,

Priya

"Mateusz Gos" <webmaster24@wp.pl> wrote in message
news:gp5v0k$dtu$1@fred.mathworks.com...
> Hi,
>
> I suppose I've got a simple question for someone who's already used to the
> new syntax for passing variables via anonymous function: Why does the
> command below not work?
>
> a = nlinfit(x,y,@(a0) myfun(a0,x,constants),a0);
>
> a0 is the initial guess of a, x is set of independent variables, y - set
> of dependent ones, constants is cell array of constant arrays/variables.
>
> the error I get is 'Too many input arguments.'
>
> I will greatly appreciate your help,
> Mateusz

Subject: nlinfit with anonymous function

From: Mateusz Gos

Date: 10 Mar, 2009 15:38:02

Message: 4 of 4

@Priya Moorthy - yah, you're right. I suppose I was unnecessarily complicating it in the first place.

Thanks both of you

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us