필터 지우기
필터 지우기

Calling a Function with multiple outputs

조회 수: 15 (최근 30일)
Mizo Amreya
Mizo Amreya 2020년 7월 10일
댓글: Mizo Amreya 2020년 7월 10일
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

채택된 답변

Arthur Roué
Arthur Roué 2020년 7월 10일
편집: Arthur Roué 2020년 7월 10일
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
Mizo Amreya
Mizo Amreya 2020년 7월 10일
Thank you, I see your logic.
It worked. I appreciated it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by