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:
undefined variable error message

Subject: undefined variable error message

From: Nathan

Date: 23 Mar, 2010 00:25:03

Message: 1 of 2

On Mar 22, 5:22 pm, "J Bell" <superblind...@gmail.com> wrote:
> This is my code:
>
> function theVal = dumb(beta,Y,X)
>
> err=Y-X*beta;
> err=abs(err);
> theVal=sum(err);
>
> end
>
> when I run it, I get the message
>
> ??? Input argument "Y" is undefined.
>
> Error in ==> dumb at 3
> err=Y-X*beta;
>
> any help?
>
> thanks
>
> why does this error message appear in general?  

How did you call the function?
Did you try running it by pressing the green triangle button?
Did you type the function name into the command window?

Do you know that you need to pass in arguments in order for your
function to work?

-Nathan

Subject: undefined variable error message

From: Herve

Date: 23 Mar, 2010 12:42:20

Message: 2 of 2

Nathan <ngreco32@gmail.com> wrote in message <902f0d33-e7cb-4e9d-9f87-a795207708c3@c20g2000prb.googlegroups.com>...
> On Mar 22, 5:22 pm, "J Bell" <superblind...@gmail.com> wrote:
> > This is my code:
> >
> > function theVal = dumb(beta,Y,X)
> >
> > err=Y-X*beta;
> > err=abs(err);
> > theVal=sum(err);
> >
> > end
> >
> > when I run it, I get the message
> >
> > ??? Input argument "Y" is undefined.
> >
> > Error in ==> dumb at 3
> > err=Y-X*beta;
> >
> > any help?
> >
> > thanks
> >
> > why does this error message appear in general?  
>
> How did you call the function?
> Did you try running it by pressing the green triangle button?
> Did you type the function name into the command window?
>
> Do you know that you need to pass in arguments in order for your
> function to work?

You can only press the run command (the green triangle button) when your function has no input arguments...
In you case, your function "dumb" has three arguments... Hence the error message.
Go to the help and look at the page "Running M-Files in the Editor".

If you want to use the command window

> x = 1:10;
> y = 2:11;
> beta = 2;
> dumb(beta,x,y)

Your dumb function must be saved in a m-file called dumb.m

Hope that helps !

Tags for this Thread

No tags are associated with 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