Effacer les filtres
Effacer les filtres

Calling a Function with multiple outputs

15 vues (au cours des 30 derniers jours)
Mizo Amreya
Mizo Amreya le 10 Juil 2020
Commenté : Mizo Amreya le 10 Juil 2020
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

Réponse acceptée

Arthur Roué
Arthur Roué le 10 Juil 2020
Modifié(e) : Arthur Roué le 10 Juil 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 commentaire
Mizo Amreya
Mizo Amreya le 10 Juil 2020
Thank you, I see your logic.
It worked. I appreciated it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by