Input a Vector as Function Argument
Mostra commenti meno recenti
Hi,
I was facing this problem in inputing a vector to my user defined function. I have defined a function that needs two inputs to perform some operations. However, when it try to pass on a vector containing two element to the function it shows need more arguments error.
x = [2 , 4]
y = sq(x)
function out = sq(a , b)
out = a.^2 + b;
end
Can somebody show me how to do it right?
I will be very grateful.
Thanks a lot!
Risposta accettata
Più risposte (1)
Use evalc
func = @(a, b) a+b
InputArgumentsNumeric = [1, 2]
InputArgumentsString = strjoin(cellstr(num2str(InputArgumentsNumeric')),',')
[~,output] = evalc("func(" + InputArgumentsString + ")")
Categorie
Scopri di più su Time Series Collections in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!