Clear Filters
Clear Filters

Calling a Function with multiple outputs

15 views (last 30 days)
Hi,
I'm trying to call a function with multiple outputs/inputs into my code.
The problelm I'm encountering is the function is returning the same value for all 3 outputs despite having different inputs and formulae.
Please advise how can I solve this issue.
This is my function:
function [lamdaT,lamdaW,lamdaO] = mobility_ratio(krw,kro,muiw,muio)
% Calculation of Mobility Ratio
% Water Mobility Ratio
lamdaW = krw/muiw;
% Water Mobility Ratio
lamdaO = kro/muio;
% Total Mobility Ratio
lamdaT = lamdaW + lamdaO;
end
This is how I'm calling it into my code:
for t=1:50
for i=1:50
lamdaW(i,t)=mobility_ratio(krw(i,t),kro(i,t),muiw,muio);
lamdaO(i,t)=mobility_ratio(krw(i,t),kro(i,t),muiw,muio);
lamdaT(i,t)=mobility_ratio(krw(i,t),kro(i,t),muiw,muio);
end
end

Accepted Answer

Arthur Roué
Arthur Roué on 10 Jul 2020
Edited: Arthur Roué on 10 Jul 2020
You should call you function this way :
for t=1:50
for i=1:50
[lamdaT(i,t), lamdaW(i,t), lamdaO(i,t)] = mobility_ratio(krw(i,t),kro(i,t),muiw,muio);
end
end
In your for loop, you call the function three time with the same inputs and you capture only the 1st output, which is the same.
  1 Comment
Mizo Amreya
Mizo Amreya on 10 Jul 2020
Thank you, I see your logic.
It worked. I appreciated it.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!