Too many Input arguments

조회 수: 1 (최근 30일)
Moyin
Moyin 2018년 1월 26일
댓글: Moyin 2018년 1월 27일
Hi all,
Can someone please explain when it's appropriate to use ~ when inputting the function arguments. I am a bit confused about this. If there is only one input argument, why can't you just write that without using ~?
I have included the part of my code below where I keep getting the error 'too many input arguments'. For clarity, qistar and k are like constants. I have also initialized dqidt0 in a separate .m script where I run it using an odesolver. dqidt is the differential of qi with respect to time.
%Code
function dqidt= LDF(qi)
TestProcess_Parameters;
qistar = qsat* bi*P_opt^vi/(1+ bi*P_opt*vi); %Calculate Equilibrium molar loading
k =(15*Dm)/Rc^2; %Mass transfer coefficient for spherical adsorbent pellets;
dqidt = k*(qistar - qi);
end
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 27일
"Can someone please explain when it's appropriate to use ~ when inputting the function arguments."
Sometimes when you write a function, you need to match an existing interface. For example you might be writing a callback function and so need to be able to accept the object and the event data, but your code might not need those inputs. You can use ~ to fill any position on the input list that you expect but whose value you will ignore.
... and sometimes when you write a function and use it for a while, you change the interface and end up not using a particular input any more. Although you could delete the input parameter that you are no longer using, you would have to simultaneously update all of the code that calls your function. That is not always practical, so sometimes you end up using ~ as a place holder so you do not need to modify the calling code.
You do not need to use ~ for a parameter: you can supply a variable name instead. However, the Just In Time compiler can be slightly more efficient when you use ~ .
  댓글 수: 1
Moyin
Moyin 2018년 1월 27일
Thank you!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by