Function with several outputs only delivers one

3 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2013-11-5
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by