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:
Using the ouput of another function to run a "new" function

Subject: Using the ouput of another function to run a "new" function

From: Saad

Date: 16 Aug, 2011 10:56:13

Message: 1 of 9

Dear all,

I hope you are well. I have a small issue in my code. I have two functions in a separate M files:

%%function 1
function P= cal(H,n)

the output here is P

%%function 2

function S= cal1(n1)

Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?

I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this? Thanks a lot


S

Subject: Using the ouput of another function to run a "new" function

From: Yannick Lebrun

Date: 16 Aug, 2011 19:18:26

Message: 2 of 9

-----------------------------------------------------------------------------------------------------------------------
"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2dicd$fki$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I hope you are well. I have a small issue in my code. I have two functions in a separate M files:
>
> %%function 1
> function P= cal(H,n)
>
> the output here is P
>
> %%function 2
>
> function S= cal1(n1)
>
> Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?
>
> I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this? Thanks a lot
>
>
> S
-----------------------------------------------------------------------------------------------------------------------
If you want to avoid using an intermediate variable "P" in order to use the function "cal1", then maybe you could try this :

S = cal1( cal(H, n) )

Not sure if it always work (may depend on the functions), but by doing so, you should get the output S in one step.

If not, then I don't really get what you mean by "using the output P without using cal". I mean, you at least need that function to evaluate the intermediate value P or whatever it should be called.

Best of luck,
- Yannick

Subject: Using the ouput of another function to run a "new" function

From: Bruno Luong

Date: 16 Aug, 2011 19:32:26

Message: 3 of 9

"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2dicd$fki$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I hope you are well. I have a small issue in my code. I have two functions in a separate M files:
>
> %%function 1
> function P= cal(H,n)
>
> the output here is P
>
> %%function 2
>
> function S= cal1(n1)
>
> Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?
>
> I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this? Thanks a lot
>

???? I don't know is someone here has a sightless idea what the hell are you talking about. I read at least three times, no chance.

Bruno

 

Subject: Using the ouput of another function to run a "new" function

From: Matt J

Date: 16 Aug, 2011 19:49:13

Message: 4 of 9

"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2dicd$fki$1@newscl01ah.mathworks.com>...
>
>
> Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?
===================


Like Bruno, I find this description quite foggy, but it occurs to me that you're talking about the same issue as in this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/269936
 

> I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this? Thanks a lot
====================

Did you change the definition of cal1 to accept an additional argument?

Subject: Using the ouput of another function to run a "new" function

From: someone

Date: 16 Aug, 2011 20:48:26

Message: 5 of 9

"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2dicd$fki$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I hope you are well. I have a small issue in my code. I have two functions in a separate M files:
>
> %%function 1
> function P= cal(H,n)
>
> the output here is P
>
> %%function 2
>
> function S= cal1(n1)
>
> Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?

If you don't call function cal, how will you calculate P?

>
> I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this?

You explicitly wrote function cal1 to accept one AND ONLY ONE input.
Why would you think it should recognize two inputs?

How is function cal1 (or S) related to P?
If n1 is a dummy input argument for P, then simply use:
S = cal1(P)

> Thanks a lot
>
>
> S

Subject: Using the ouput of another function to run a "new" function

From: Saad

Date: 18 Aug, 2011 10:35:09

Message: 6 of 9

"someone" wrote in message <j2el2q$ev9$1@newscl01ah.mathworks.com>...
> "Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2dicd$fki$1@newscl01ah.mathworks.com>...
> > Dear all,
> >
> > I hope you are well. I have a small issue in my code. I have two functions in a separate M files:
> >
> > %%function 1
> > function P= cal(H,n)
> >
> > the output here is P
> >
> > %%function 2
> >
> > function S= cal1(n1)
> >
> > Here the output is "S". Now to get "S" I need to use the output of function "cal". My aim is to use the output P without calling "cal". how can I do that please?
>
> If you don't call function cal, how will you calculate P?
>
> >
> > I tried S= cal1(n1,P) but it doesnt recognize P . Could you please help me on this?
>
> You explicitly wrote function cal1 to accept one AND ONLY ONE input.
> Why would you think it should recognize two inputs?
>
> How is function cal1 (or S) related to P?
> If n1 is a dummy input argument for P, then simply use:
> S = cal1(P)
>
> > Thanks a lot
> >
> >
> > S
Hi all
Sorry for the confusion. I hope that this email will clarify everything.

I have function 2 m-files
%% function1%%

 function P= cal(H,n)

the output here is P. P is scalar for example

%%function 2%%%

function S= cal1(n1,P)

%%the function 2 is also dependent on P

%%in this case to get the output S I need to define P and n1 right?
%%for example
P=cal(H,n)
n1=2;

S=P/2;

P is an output for function "cal" and so to define P in "cal1" it I need to write P=cal(H,n). My question is:

Is there any other way I could use the output P without writing "P=cal(H,n)" because when I do this way it slows down the code. In other words, is there any other intelligent way of writing my function "cal1"?

Thank you and apologies for the confusion

Subject: Using the ouput of another function to run a "new" function

From: Matt J

Date: 18 Aug, 2011 13:47:09

Message: 7 of 9

"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2ipst$kss$1@newscl01ah.mathworks.com>...
>
> P is an output for function "cal" and so to define P in "cal1" it I need to write P=cal(H,n).
==================

No, it's not clear why you need to do this. In your function definition
S= cal1(n1,P)
if appears that the user is supposed to pass P to cal1 as an input argument. If that's true, why do you need to recompute P from scratch using cal(H,n)


> Thank you and apologies for the confusion
=======================

As soon as you actually clear up the confusion, I'm sure we'll forgive you.

Subject: Using the ouput of another function to run a "new" function

From: Saad

Date: 19 Aug, 2011 09:11:09

Message: 8 of 9

"Matt J" wrote in message <j2j54t$qa5$1@newscl01ah.mathworks.com>...
> "Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2ipst$kss$1@newscl01ah.mathworks.com>...
> >
> > P is an output for function "cal" and so to define P in "cal1" it I need to write P=cal(H,n).
> ==================
>
> No, it's not clear why you need to do this. In your function definition
> S= cal1(n1,P)
> if appears that the user is supposed to pass P to cal1 as an input argument. If that's true, why do you need to recompute P from scratch using cal(H,n)
>
>
> > Thank you and apologies for the confusion
> =======================
>
> As soon as you actually clear up the confusion, I'm sure we'll forgive you.


Matt

Thats actually my biggest confusion when I compute P=cal(H,n) in separate m file. and pass P as an argument to "cal1" in this way S= cal1(n1,P), normally I dont need to recompute P from scratch as you said. But when I run the the function "cal1(n1,P)" it says P undefined. I dont know where I have done the mistake? Any idea?

Thank you

Saad

Subject: Using the ouput of another function to run a "new" function

From: Matt J

Date: 19 Aug, 2011 13:10:10

Message: 9 of 9

"Saad " <saad.badaoui07@imperial.ac.uk> wrote in message <j2l9bd$pf6$1@newscl01ah.mathworks.com>...
>
> Thats actually my biggest confusion when I compute P=cal(H,n) in separate m file. and pass P as an argument to "cal1" in this way S= cal1(n1,P), normally I dont need to recompute P from scratch as you said. But when I run the the function "cal1(n1,P)" it says P undefined. I dont know where I have done the mistake? Any idea?
====================

Possibly you cleared P by mistake prior to calling cal1. Set a breakpoint to check.

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