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:
neural network into a function

Subject: neural network into a function

From: kentavros babis

Date: 24 Feb, 2009 15:12:01

Message: 1 of 5

I have created a neural network with neural network toolbox called ann1, which takes one input and gives one output. I run for example sim(ann1,1) and get sim(ann1,1)
ans =0.9231. Then i try to write a function function
 G = obj(x)
G=sim(ann1,x);
and the following error occurs
 obj(1)
??? Undefined function or variable 'ann1'.

Error in ==> obj at 2
G=sim(ann1,x);
Does anyone know why this happens?

Subject: neural network into a function

From: Steven Lord

Date: 24 Feb, 2009 16:51:22

Message: 2 of 5


"kentavros babis" <akentavros@yahoo.com> wrote in message
news:go12o1$lin$1@fred.mathworks.com...
>I have created a neural network with neural network toolbox called ann1,
>which takes one input and gives one output. I run for example sim(ann1,1)
>and get sim(ann1,1)
> ans =0.9231. Then i try to write a function

I assume your function file is:

function G = obj(x)
G=sim(ann1,x);

> and the following error occurs
> obj(1)
> ??? Undefined function or variable 'ann1'.
>
> Error in ==> obj at 2
> G=sim(ann1,x);
> Does anyone know why this happens?

You're not passing ann1 into the obj function's workspace, so it has no idea
what ann1 is. Remember, each function has its own workspace, and unless you
pass a variable into that function as an input or create the variable inside
the function (or use a few other techniques I'm not going to get into here)
the variable can't be used in that function.

--
Steve Lord
slord@mathworks.com

Subject: neural network into a function

From: kentavros babis

Date: 25 Feb, 2009 15:32:02

Message: 3 of 5

"Steven Lord" <slord@mathworks.com> wrote in message <go18ia$8op$1@fred.mathworks.com>...
>
> "kentavros babis" <akentavros@yahoo.com> wrote in message
> news:go12o1$lin$1@fred.mathworks.com...
> >I have created a neural network with neural network toolbox called ann1,
> >which takes one input and gives one output. I run for example sim(ann1,1)
> >and get sim(ann1,1)
> > ans =0.9231. Then i try to write a function
>
> I assume your function file is:
>
> function G = obj(x)
> G=sim(ann1,x);
>
> > and the following error occurs
> > obj(1)
> > ??? Undefined function or variable 'ann1'.
> >
> > Error in ==> obj at 2
> > G=sim(ann1,x);
> > Does anyone know why this happens?
>
> You're not passing ann1 into the obj function's workspace, so it has no idea
> what ann1 is. Remember, each function has its own workspace, and unless you
> pass a variable into that function as an input or create the variable inside
> the function (or use a few other techniques I'm not going to get into here)
> the variable can't be used in that function.
>
> --
> Steve Lord
> slord@mathworks.com
>

Could you please give a hint onto how to call a variable from another workspace into obj function workspace?

Subject: neural network into a function

From: kentavros babis

Date: 25 Feb, 2009 15:33:01

Message: 4 of 5

"Steven Lord" <slord@mathworks.com> wrote in message <go18ia$8op$1@fred.mathworks.com>...
>
> "kentavros babis" <akentavros@yahoo.com> wrote in message
> news:go12o1$lin$1@fred.mathworks.com...
> >I have created a neural network with neural network toolbox called ann1,
> >which takes one input and gives one output. I run for example sim(ann1,1)
> >and get sim(ann1,1)
> > ans =0.9231. Then i try to write a function
>
> I assume your function file is:
>
> function G = obj(x)
> G=sim(ann1,x);
>
> > and the following error occurs
> > obj(1)
> > ??? Undefined function or variable 'ann1'.
> >
> > Error in ==> obj at 2
> > G=sim(ann1,x);
> > Does anyone know why this happens?
>
> You're not passing ann1 into the obj function's workspace, so it has no idea
> what ann1 is. Remember, each function has its own workspace, and unless you
> pass a variable into that function as an input or create the variable inside
> the function (or use a few other techniques I'm not going to get into here)
> the variable can't be used in that function.
>
> --
> Steve Lord
> slord@mathworks.com
>

Could you please give a hint onto how to call a variable from another workspace into obj function workspace?

Subject: neural network into a function

From: Greg Heath

Date: 2 Mar, 2009 17:09:11

Message: 5 of 5

On Feb 25, 10:33=A0am, "kentavros babis" <akentav...@yahoo.com> wrote:
> "Steven Lord" <sl...@mathworks.com> wrote in message <go18ia$8o...@fred.m=
athworks.com>...
>
> > "kentavros babis" <akentav...@yahoo.com> wrote in message
> >news:go12o1$lin$1@fred.mathworks.com...
> > >I have created aneuralnetwork withneuralnetwork toolbox called ann1,
> > >which takes one input and gives one output. I run for example sim(ann1=
,1)
> > >and get =A0sim(ann1,1)
> > > ans =3D0.9231. Then i try to write a function
>
> > I assume your function file is:
>
> > function G =3D obj(x)
> > G=3Dsim(ann1,x);
>
> > > and the following error occurs
> > > obj(1)
> > > ??? Undefined function or variable 'ann1'.
>
> > > Error in =3D=3D> obj at 2
> > > G=3Dsim(ann1,x);
> > > Does anyone know why this happens?
>
> > You're not passing ann1 into the obj function's workspace, so it has no=
 idea
> > what ann1 is. =A0Remember, each function has its own workspace, and unl=
ess you
> > pass a variable into that function as an input or create the variable i=
nside
> > the function (or use a few other techniques I'm not going to get into h=
ere)
> > the variable can't be used in that function.
>
> > --
> > Steve Lord
> > sl...@mathworks.com
>
> Could you please give a hint onto how to call a variable from another wor=
kspace into obj function workspace?- Hide quoted text -
>
> - Show quoted text -

Try

help global

Hope this helps.

Greg

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