Function with several outputs only delivers one

3 views (last 30 days)
Hi
Im trying to creat a function thats supposed to give me several outputs. Each of them are a single value.
function[HeightGC,HMudafterLoss,t,vgass]=Kick(input1,input2,...)
and yet when i call it I only get 1 output. I tried plot all the outputs to verify that the data is calculated properly and it is. So then I wonder how I can call this function and make it give me all the values? As of now im only getting out 1 value like this
ans = thevalue
And a second question If i get the thing to work I want to call it in another function giving and giving the variables names at the same time. I tried this way of doing it:
[HeightGC,HMudafterLoss,t,vgass]=Kick(QSlam,Area,NrWells,TVD,IDcasing,BitDia,tDetect,Skin,initialmuddensity,Loss)
is that the correct way? If not plz guide me in the correct direction.
Thanks in advance!
Kjetil Nøkling
Please help a matlab beginner.

Answers (1)

Walter Roberson
Walter Roberson on 5 Nov 2013
In MATLAB, if you are assigning the output of the function to a list of locations, then the number of outputs that will be delivered is the number of outputs in the list. If, however, you are not assigning the output of the function to a list of locations, then the number of outputs that will be delivered is one.
Kick(input1,input2,...)
will deliver only one output because the output is not being assigned anywhere.
exp(-5 * Kick(input1,input2,...))
will still have Kick deliver only one output, as the output is not being assigned before being used.
[A, B] = Kick(input1,input2,...)
will deliver two outputs as that is the number of elements in the list of locations being assigned to.
[A, B, C, D] = Kick(input1,input2,...)
will deliver all four outputs, assigning the function's HeightGC into A, HMudafterLoss into B, and so on.
Notice that the output variable names in the calling routine do not need to be the same as the names internal to the function.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!