Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to call a function inside the code

0 views
Skip to first unread message

Seyma

unread,
Dec 31, 2011, 8:56:08 AM12/31/11
to
Hi,

I have written a very simple function(in a file called stat.m) like

function y = stat(x)
y = x+5;

When i want to call this function from another file like

a = stat(5);
a

I get an error saying

Input argument "x" is undefined.

Error in ==> stat at 2
y = x+5;


When i call the function from the command line, it is OK. However, this is not what i want. How can i call the stat function inside the code file?

Thanks.

dpb

unread,
Dec 31, 2011, 9:51:22 AM12/31/11
to
Looks ok from what you posted.

What does

which stat

return?

I'd guess you either have another variable stat from an earlier testing
of the function or by accident or there's a stale copy getting loaded.

Try

clear stat

and try again. If no joy report back on what the which command returned

--


dpb

unread,
Dec 31, 2011, 10:01:31 AM12/31/11
to
On 12/31/2011 8:51 AM, dpb wrote:
...

> I'd guess you either have another variable stat from an earlier testing
> of the function or by accident or there's a stale copy getting loaded.

...

Whoops! Sent before edit...

A variable stat wouldn't be the same error so my bet is on the stale copy.

And, of course, it is that the old copy may be cached in memory, not
getting loaded that the

clear stat

will resolve

Oh, another thought...

Is there by any chance from earlier edits an internal function in the
calling routine m-file also name stat (maybe from before you decided to
move it to its own m-file to be externally callable) that doesn't have
the argument or has a typo between the argument and the used variable or
somesuch?

That would explain why the function would work from the command line but
not from the particular m-file that called it.

--

--

Seyma

unread,
Dec 31, 2011, 10:06:08 AM12/31/11
to
dpb <no...@non.net> wrote in message <jdn7ha$lvf$1...@speranza.aioe.org>...
i got the idea. I opened a new .m file with another name and paste the very same code in it and it did well!

Thank you very much for your reply.

dpb

unread,
Dec 31, 2011, 10:41:38 AM12/31/11
to
On 12/31/2011 9:06 AM, Seyma wrote:
...

> i got the idea. I opened a new .m file with another name and paste the
> very same code in it and it did well!
>
> Thank you very much for your reply.

No problem...see other followup for a better explanation of what may
have actually been the problem than I wrote above.

--

0 new messages