How to skip inputs in a function?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
David Hill
el 23 de Feb. de 2022
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.
Respuestas (1)
Voss
el 25 de Feb. de 2022
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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!