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 Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by