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:
attempt to execute script varargin as a function

Subject: attempt to execute script varargin as a function

From: Dave Brackett

Date: 1 Sep, 2008 10:16:35

Message: 1 of 9

I have been trying to use the Hybrid Particle Swarm
Optimization function from the file exchange by Alexandros
Leontitsis:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=6497&objectType=file

I am running this from within an m file but keep getting
the following error message:

??? Attempt to execute SCRIPT varargin as a function:
C:\Program
Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m

Error in ==> main_vectorised at 160
    options=hPSOoptions(varargin);

Anyone any ideas on how to avoid this problem? Thanks.

Subject: attempt to execute script varargin as a function

From: heiko_marx@hotmail.com

Date: 1 Sep, 2008 12:04:20

Message: 2 of 9

On 1 Sep., 12:16, "Dave Brackett" <davebrack...@hotmail.com> wrote:
> I have been trying to use the Hybrid Particle Swarm
> Optimization function from the file exchange by Alexandros
> Leontitsis:
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> .do?objectId=3D6497&objectType=3Dfile
>
> I am running this from within an m file but keep getting
> the following error message:
>
> ??? Attempt to execute SCRIPT varargin as a function:
> C:\Program
> Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> Error in =3D=3D> main_vectorised at 160
> =A0 =A0 options=3DhPSOoptions(varargin);
>
> Anyone any ideas on how to avoid this problem? Thanks.

Hi.

Do you have any input arguments in your function main_vectorised? Is
the variable varargin existing at this point in the code?

Heiko

Subject: attempt to execute script varargin as a function

From: Dave

Date: 1 Sep, 2008 13:04:53

Message: 3 of 9

On Sep 1, 1:04=A0pm, heiko_m...@hotmail.com wrote:
> On 1 Sep., 12:16, "Dave Brackett" <davebrack...@hotmail.com> wrote:
>
>
>
>
>
> > I have been trying to use the Hybrid Particle Swarm
> > Optimization function from the file exchange by Alexandros
> > Leontitsis:
>
> >http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> > .do?objectId=3D6497&objectType=3Dfile
>
> > I am running this from within an m file but keep getting
> > the following error message:
>
> > ??? Attempt to execute SCRIPT varargin as a function:
> > C:\Program
> > Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> > Error in =3D=3D> main_vectorised at 160
> > =A0 =A0 options=3DhPSOoptions(varargin);
>
> > Anyone any ideas on how to avoid this problem? Thanks.
>
> Hi.
>
> Do you have any input arguments in your function main_vectorised? Is
> the variable varargin existing at this point in the code?
>
> Heiko- Hide quoted text -
>
> - Show quoted text -

If you look at this help reference:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/varargin.html
you will see that varargin is short for variable length input argument
list and so shouldn't need defining prior to using it, or so I
believe. have you used varargin before from within a function? Thanks
for your reply. Dave

Subject: attempt to execute script varargin as a function

From: woodchips@rochester.rr.com

Date: 1 Sep, 2008 13:50:53

Message: 4 of 9

On Sep 1, 6:16=A0am, "Dave Brackett" <davebrack...@hotmail.com> wrote:
> I have been trying to use the Hybrid Particle Swarm
> Optimization function from the file exchange by Alexandros
> Leontitsis:
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> .do?objectId=3D6497&objectType=3Dfile
>
> I am running this from within an m file but keep getting
> the following error message:
>
> ??? Attempt to execute SCRIPT varargin as a function:
> C:\Program
> Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> Error in =3D=3D> main_vectorised at 160
> =A0 =A0 options=3DhPSOoptions(varargin);
>
> Anyone any ideas on how to avoid this problem? Thanks.

What you need to show us, is how you called that
tool.

John

Subject: attempt to execute script varargin as a function

From: Dave

Date: 1 Sep, 2008 14:28:42

Message: 5 of 9

On Sep 1, 2:50=A0pm, woodch...@rochester.rr.com wrote:
> On Sep 1, 6:16=A0am, "Dave Brackett" <davebrack...@hotmail.com> wrote:
>
>
>
>
>
> > I have been trying to use the Hybrid Particle Swarm
> > Optimization function from the file exchange by Alexandros
> > Leontitsis:
>
> >http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> > .do?objectId=3D6497&objectType=3Dfile
>
> > I am running this from within an m file but keep getting
> > the following error message:
>
> > ??? Attempt to execute SCRIPT varargin as a function:
> > C:\Program
> > Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> > Error in =3D=3D> main_vectorised at 160
> > =A0 =A0 options=3DhPSOoptions(varargin);
>
> > Anyone any ideas on how to avoid this problem? Thanks.
>
> What you need to show us, is how you called that
> tool.
>
> John- Hide quoted text -
>
> - Show quoted text -

ok, it was done like this where the functions are the hybrid pso from
the file exchange:

options=3DhPSOoptions(variable_range,varargin);
[x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options,varargin);

please ask if you need any more details. thanks. Dave

Subject: attempt to execute script varargin as a function

From: dpb

Date: 1 Sep, 2008 14:46:27

Message: 6 of 9

Dave wrote:
> On Sep 1, 2:50 pm, woodch...@rochester.rr.com wrote:
>> On Sep 1, 6:16 am, "Dave Brackett" <davebrack...@hotmail.com> wrote:
>>
...
>>> I am running this from within an m file but keep getting
>>> the following error message:
>>> ??? Attempt to execute SCRIPT varargin as a function:
>>> C:\Program Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>>> Error in ==> main_vectorised at 160
>>> options=hPSOoptions(varargin);
>>> Anyone any ideas on how to avoid this problem? Thanks.
>> What you need to show us, is how you called that
>> tool.
...
> ok, it was done like this ...
>
> options=hPSOoptions(variable_range,varargin);

As the error message says, you tried to use varargin in a place that
requires a set of input variables.

"varargin" is a built-in Matlab function, not a stand in name for the
variables which the function hPSOoptions is expecting to do something
with internally.

Read the help w/ the FEX functions to see what is expected to be passed,
but it will have to be a variable or an array (or perhaps even nothing
if there are defaults supplied internal to the function for all possible
inputs), but it can't be a Matlab-reserved keyword or function.

--

> [x,fval,gfx,output]=hPSO(fitness_fcn,no_variables,options,varargin);

Ditto above...

--

Subject: attempt to execute script varargin as a function

From: woodchips@rochester.rr.com

Date: 1 Sep, 2008 14:51:32

Message: 7 of 9

On Sep 1, 10:28=A0am, Dave <davebrack...@hotmail.com> wrote:
> On Sep 1, 2:50=A0pm, woodch...@rochester.rr.com wrote:
>
>
>
> > On Sep 1, 6:16=A0am, "Dave Brackett" <davebrack...@hotmail.com> wrote:
>
> > > I have been trying to use the Hybrid Particle Swarm
> > > Optimization function from the file exchange by Alexandros
> > > Leontitsis:
>
> > >http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> > > .do?objectId=3D6497&objectType=3Dfile
>
> > > I am running this from within an m file but keep getting
> > > the following error message:
>
> > > ??? Attempt to execute SCRIPT varargin as a function:
> > > C:\Program
> > > Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> > > Error in =3D=3D> main_vectorised at 160
> > > =A0 =A0 options=3DhPSOoptions(varargin);
>
> > > Anyone any ideas on how to avoid this problem? Thanks.
>
> > What you need to show us, is how you called that
> > tool.
>
> > John- Hide quoted text -
>
> > - Show quoted text -
>
> ok, it was done like this where the functions are the hybrid pso from
> the file exchange:
>
> options=3DhPSOoptions(variable_range,varargin);
> [x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options,varargin);
>
> please ask if you need any more details. thanks. Dave

Why are you passing in varargin?

varargin is NOT a variable that you should pass in.

Read the help for the hPSO tools. Learn how
to call them as they are designed to be called.

John

Subject: attempt to execute script varargin as a function

From: Dave

Date: 1 Sep, 2008 15:15:25

Message: 8 of 9

On Sep 1, 3:51=A0pm, woodch...@rochester.rr.com wrote:
> On Sep 1, 10:28=A0am, Dave <davebrack...@hotmail.com> wrote:
>
>
>
>
>
> > On Sep 1, 2:50=A0pm, woodch...@rochester.rr.com wrote:
>
> > > On Sep 1, 6:16=A0am, "Dave Brackett" <davebrack...@hotmail.com> wrote=
:
>
> > > > I have been trying to use the Hybrid Particle Swarm
> > > > Optimization function from the file exchange by Alexandros
> > > > Leontitsis:
>
> > > >http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> > > > .do?objectId=3D6497&objectType=3Dfile
>
> > > > I am running this from within an m file but keep getting
> > > > the following error message:
>
> > > > ??? Attempt to execute SCRIPT varargin as a function:
> > > > C:\Program
> > > > Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> > > > Error in =3D=3D> main_vectorised at 160
> > > > =A0 =A0 options=3DhPSOoptions(varargin);
>
> > > > Anyone any ideas on how to avoid this problem? Thanks.
>
> > > What you need to show us, is how you called that
> > > tool.
>
> > > John- Hide quoted text -
>
> > > - Show quoted text -
>
> > ok, it was done like this where the functions are the hybrid pso from
> > the file exchange:
>
> > options=3DhPSOoptions(variable_range,varargin);
> > [x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options,varargin);
>
> > please ask if you need any more details. thanks. Dave
>
> Why are you passing in varargin?
>
> varargin is NOT a variable that you should pass in.
>
> Read the help for the hPSO tools. Learn how
> to call them as they are designed to be called.
>
> John- Hide quoted text -
>
> - Show quoted text -

There actually is not much help for these functions. I have worked out
that it can just be excluded such that it is called like this:

options=3DhPSOoptions(variable_range);
[x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options);

Thanks for your help with this.

Subject: attempt to execute script varargin as a function

From: heiko_marx@hotmail.com

Date: 2 Sep, 2008 06:10:59

Message: 9 of 9

On 1 Sep., 17:15, Dave <davebrack...@hotmail.com> wrote:
> On Sep 1, 3:51=A0pm, woodch...@rochester.rr.com wrote:
>
>
>
> > On Sep 1, 10:28=A0am, Dave <davebrack...@hotmail.com> wrote:
>
> > > On Sep 1, 2:50=A0pm, woodch...@rochester.rr.com wrote:
>
> > > > On Sep 1, 6:16=A0am, "Dave Brackett" <davebrack...@hotmail.com> wro=
te:
>
> > > > > I have been trying to use the Hybrid Particle Swarm
> > > > > Optimization function from the file exchange by Alexandros
> > > > > Leontitsis:
>
> > > > >http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> > > > > .do?objectId=3D6497&objectType=3Dfile
>
> > > > > I am running this from within an m file but keep getting
> > > > > the following error message:
>
> > > > > ??? Attempt to execute SCRIPT varargin as a function:
> > > > > C:\Program
> > > > > Files\MATLAB\R2008a\toolbox\matlab\lang\varargin.m
>
> > > > > Error in =3D=3D> main_vectorised at 160
> > > > > =A0 =A0 options=3DhPSOoptions(varargin);
>
> > > > > Anyone any ideas on how to avoid this problem? Thanks.
>
> > > > What you need to show us, is how you called that
> > > > tool.
>
> > > > John- Hide quoted text -
>
> > > > - Show quoted text -
>
> > > ok, it was done like this where the functions are the hybrid pso from
> > > the file exchange:
>
> > > options=3DhPSOoptions(variable_range,varargin);
> > > [x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options,varargin)=
;
>
> > > please ask if you need any more details. thanks. Dave
>
> > Why are you passing in varargin?
>
> > varargin is NOT a variable that you should pass in.
>
> > Read the help for the hPSO tools. Learn how
> > to call them as they are designed to be called.
>
> > John- Hide quoted text -
>
> > - Show quoted text -
>
> There actually is not much help for these functions. I have worked out
> that it can just be excluded such that it is called like this:
>
> options=3DhPSOoptions(variable_range);
> [x,fval,gfx,output]=3DhPSO(fitness_fcn,no_variables,options);
>
> Thanks for your help with this.

Hi again.

I think you have to know what varargin in MatLab actually is meant to
be. MatLab functions define input and output arguments. There are two
main approaches to define a function:

1. Assign input and output arguments directly to variables, i.e.
    [a, b, c] =3D fun_name(in1, in2);

    Here, the function takes two input arguments and stores them for
internal use into the variables in1 and in2.
    It also outputs three arguments that have to be created inside the
function.

2. The number and type of input and output arguments is variable:
    varargout =3D fun_name(varargin);

    MatLab allows functions to have a variable interface for
functions. In this case, all input arguments are stored
    in a cell array named varargin, with nargin elements. You can
access these with varargin{1} ... varargin{nargin}.
    Analog, you have to assign all output variables to varargout,
where the number of output arguments that the
    function was called with is nargout (i.e. [a, b] =3D fun_name(in1) -
> nargout =3D 2, nargin =3D 1). See the doc.

So if the help for hPSO states that hPSO takes varargin as one of the
input arguments, it means that you can pass a flexible number of input
arguments explained further in the help somewhere. It also means, that
if your function receives varargin when it is called you can pass this
cell array directly to hPSO if it contains valid options, like:

function my_fun(varargin)
    out =3D hPSO(varargin);

This is what I meant with my first answer: if inside your call the
variable varargin is existing, this error should not appear.
Otherwise, replace varargin by valid options, like:

    out =3D hPSO(opt1, opt2, ...);

Hope this helps,
Heiko

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