Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Call another function!

Subject: Call another function!

From: Erik Andersson

Date: 15 May, 2008 17:37:02

Message: 1 of 7

I've got the following function:

function taborttrend
x=load('data.txt');
V=diff(x,1);

Now a want to call another function lying in the same
directory as taborttrend.m named trend.m which has input x,
i.e trend(x). Now a want my differenced vektor V to be that
input x and that its done in the m-file taborttrend. How do
a get that?

Thanks for answers!

Subject: Re: Call another function!

From: helper

Date: 15 May, 2008 17:51:02

Message: 2 of 7

"Erik Andersson" <annerk02@student.umu.se> wrote in message
<g0hsbt$bvj$1@fred.mathworks.com>...
> I've got the following function:
>
> function taborttrend
> x=load('data.txt');
> V=diff(x,1);
>
> Now a want to call another function lying in the same
> directory as taborttrend.m named trend.m which has input
x,
> i.e trend(x). Now a want my differenced vektor V to be
that
> input x and that its done in the m-file taborttrend. How
do
> a get that?
>
> Thanks for answers!


If I understand your question right, you want to use:

function taborttrend
x=load('data.txt');
V=diff(x,1);
trend(V)

Note that when you call a specific function (as you are
doing with TREND), it doesn't matter what the name of the
input variable is within that function. You can pass any
variable you want.

If you defined TREND to be:

 function trend(x)

You don't have to call TREND using "x", however, within
TREND, you must use "x" to reference the passed-in value.

I hope this addresses and answers your question.

Subject: Re: Call another function!

From: Erik Andersson

Date: 15 May, 2008 17:56:01

Message: 3 of 7

"Erik Andersson" <annerk02@student.umu.se> wrote in message
<g0hsbt$bvj$1@fred.mathworks.com>...
> I've got the following function:
>
> function taborttrend
> x=load('data.txt');
> V=diff(x,1);
>
> Now a want to call another function lying in the same
> directory as taborttrend.m named trend.m which has input
x,
> i.e trend(x). Now a want my differenced vektor V to be
that
> input x and that its done in the m-file taborttrend. How
do
> a get that?
>
> Thanks for answers!

I've tried:

function taborttrend
 x=load('data.txt');
 V=diff(x,1);
 trend(V)

But it doesn't work. Why?

Subject: Re: Call another function!

From: someone

Date: 15 May, 2008 19:49:03

Message: 4 of 7

"Erik Andersson" <annerk02@student.umu.se> wrote in message
<g0htfh$imr$1@fred.mathworks.com>...
> "Erik Andersson" <annerk02@student.umu.se> wrote in
message
> <g0hsbt$bvj$1@fred.mathworks.com>...
> > I've got the following function:
> >
> > function taborttrend
> > x=load('data.txt');
> > V=diff(x,1);
> >
> > Now a want to call another function lying in the same
> > directory as taborttrend.m named trend.m which has
input
> x,
> > i.e trend(x). Now a want my differenced vektor V to be
> that
> > input x and that its done in the m-file taborttrend.
How
> do
> > a get that?
> >
> > Thanks for answers!
>
> I've tried:
>
> function taborttrend
> x=load('data.txt');
> V=diff(x,1);
> trend(V)
>
> But it doesn't work. Why?

This is like saying, "I tried to walk, but I fell. Why?"
There could be MANY reasons.

How do you know it didn't work?

What error message did you get?

What is the code in function trend?

Subject: Re: Call another function!

From: helper

Date: 15 May, 2008 20:10:20

Message: 5 of 7

> I've tried:
>
> function taborttrend
> x=load('data.txt');
> V=diff(x,1);
> trend(V)
>
> But it doesn't work. Why?

I think your flux capacitor overloaded the triple value of
the third exigency. You might want to uplink with the
fluid portion of the apogee.

Or....post your error message. Whichever is easier.

Subject: Re: Call another function!

From: Erik Andersson

Date: 16 May, 2008 12:22:01

Message: 6 of 7


>
> I think your flux capacitor overloaded the triple value
of
> the third exigency. You might want to uplink with the
> fluid portion of the apogee.
>
> Or....post your error message. Whichever is easier.
>

This is what i get:

??? Error using ==> load
Argument must contain a string.

Error in ==> trend at 3
V=load(x);

Error in ==> taborttrend at 4
trend(x)

x in this case I want to be my vector V created in the
function taborttrend


Subject: Re: Call another function!

From: Peter Boettcher

Date: 16 May, 2008 13:29:27

Message: 7 of 7

"Erik Andersson" <annerk02@student.umu.se> writes:

>>
>> I think your flux capacitor overloaded the triple value
> of
>> the third exigency. You might want to uplink with the
>> fluid portion of the apogee.
>>
>> Or....post your error message. Whichever is easier.
>>
>
> This is what i get:
>
> ??? Error using ==> load
> Argument must contain a string.
>
> Error in ==> trend at 3
> V=load(x);
>
> Error in ==> taborttrend at 4
> trend(x)
>
> x in this case I want to be my vector V created in the
> function taborttrend

If you load your data in the outer function (taborttrend), then you do
not need to load the data inside your trend function. I would think you
want your trend function to take as an input the data itself. That
means, define the function as:

function <whatever your output variable is> = trend(V)

and eliminate the V=load(x) line.

Your taborttrend function has already done the V=load(x), so you can
then simply pass V to the "trend" function, like you are currently doing.

-Peter

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics