How to skip inputs in a function?
21 ビュー (過去 30 日間)
古いコメントを表示
I have a function: y= signal(T,T_set,P,I, D, N)
There's a variable x which equals to T- T_set.
If the length of x equals 1, I need to skip the D and I terms of the function.
This is what I have so far:
function y= signal(T,T_set,P,I, D, N)
x= T- T_set
k=length(x)
if k==1
How do I proceed to skip D and I?
1 件のコメント
David Hill
2022 年 2 月 23 日
Don't understand your question. You don't have to use the inputs in your function and certainly don't have to use them in any order.
回答 (1 件)
Voss
2022 年 2 月 25 日
If you mean that you want to be able to call the function with on or the other of two different sets of input arguments, one set being T,T_set,P,I,D,N (in that order) and the other set being T,T_set,P,N (in that order) (and whether the length of x = T-T_set equals 1 is how you can determine which set of inputs is being given), then you can do something like this:
function y= signal(T,T_set,P,I, D, N)
x= T- T_set
k=length(x)
if k==1
% in this case, the fourth input argument "I"
% is actually the value of N
N = I;
end
But if that's what you want to do it's probably clearer to use the nargin() function to tell you the number of input arguments given, in which case the dependence on length(x) == 1 is lost:
function y= signal(T,T_set,P,I, D, N)
if nargin == 4
% in this case, the fourth input argument "I"
% is actually the value of N
N = I;
end
It's hard to know if using nargin() instead of length(x) == 1 is a good idea here without knowing more about what the function is supposed to do and how it's supposed to be used.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!