Borrar filtros
Borrar filtros

Calling a Function with multiple outputs

15 visualizaciones (últimos 30 días)
Mizo Amreya
Mizo Amreya el 10 de Jul. de 2020
Comentada: Mizo Amreya el 10 de Jul. de 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

Respuesta aceptada

Arthur Roué
Arthur Roué el 10 de Jul. de 2020
Editada: Arthur Roué el 10 de Jul. de 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 comentario
Mizo Amreya
Mizo Amreya el 10 de Jul. de 2020
Thank you, I see your logic.
It worked. I appreciated it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by