Not enough input arguments error in function
Mostra commenti meno recenti
Hello All,
I am very new in matlab and write the below function and i got a two errors
function y = organization_Performance_multiobjective (x)
y(1)=(-0.144*x(1)-0.077*x(2)-0.053*x(3)+0.097*x(4)-0.057*x(5)+0.066*x(6)-0.037*x(7)+0.142*x(8)+0.17*x(9)+0.048*x(10)+0.042*x(11)-0.011*x(12));
y(2)=0.235*x(4)+0.038*x(5)+0.248*x(6)-0.025*x(7)+0.155*x(8)-0.231*x(9)-0.054*x(10)-0.002*x(11)+0.012*x(12);
y(3)=0.047*x(1)+0.202*x(2)-0.053*x(3)-0.19*x(6)-0.061*x(7)-0.101*x(8)+0.074*x(9)-0.203*x(10)-0.066*x(11)+0.005*x(12);
y(4)=0.06*x(1)+0.058*x(2)-0.187*x(3)+0.002*x(4)+0.004*x(5)+0.41*x(11)-0.279*x(12);
y(5)=-0.04*x(1)-0.011*x(2)+0.002*x(3)-0.009*x(4)+0.104*x(5)-0.35*x(6)-0.038*x(7)-0.256*x(8)+0.164*x(9)+0.027*x(10);
end
and i give a arry to this function consists from 12 numbers and i got the below error
Not enough input arguments.
Error in organization_Performance_multiobjective (line 2)
y(1)=(-0.144*x(1)-0.077*x(2)-0.053*x(3)+0.097*x(4)-0.057*x(5)+0.066*x(6)-0.037*x(7)+0.142*x(8)+0.17*x(9)+0.048*x(10)+0.042*x(11)-0.011*x(12));
Risposte (2)
Alan Stevens
il 13 Mar 2021
The following works for me (I['ve chosen random numbers for x as you didn't say what ones you used):
x = rand(1,12);
y = organization_Performance_multiobjective (x);
disp(y)
function y = organization_Performance_multiobjective (x)
y(1)=(-0.144*x(1)-0.077*x(2)-0.053*x(3)+0.097*x(4)-0.057*x(5)+0.066*x(6)-0.037*x(7)+0.142*x(8)+0.17*x(9)+0.048*x(10)+0.042*x(11)-0.011*x(12));
y(2)=0.235*x(4)+0.038*x(5)+0.248*x(6)-0.025*x(7)+0.155*x(8)-0.231*x(9)-0.054*x(10)-0.002*x(11)+0.012*x(12);
y(3)=0.047*x(1)+0.202*x(2)-0.053*x(3)-0.19*x(6)-0.061*x(7)-0.101*x(8)+0.074*x(9)-0.203*x(10)-0.066*x(11)+0.005*x(12);
y(4)=0.06*x(1)+0.058*x(2)-0.187*x(3)+0.002*x(4)+0.004*x(5)+0.41*x(11)-0.279*x(12);
y(5)=-0.04*x(1)-0.011*x(2)+0.002*x(3)-0.009*x(4)+0.104*x(5)-0.35*x(6)-0.038*x(7)-0.256*x(8)+0.164*x(9)+0.027*x(10);
end
Jan
il 13 Mar 2021
How do you call this code? Do you use the green triangle in the editor? Then the function is called without input arguments. See Alan's answer for an example, how you call the function with an argument.
By the way, compare:
y(1)=(-0.144*x(1)-0.077*x(2)-0.053*x(3)+0.097*x(4)-0.057*x(5)+0.066*x(6)-0.037*x(7)+0.142*x(8)+0.17*x(9)+0.048*x(10)+0.042*x(11)-0.011*x(12));
with:
y(1) = [-0.144, -0.077, -0.053, 0.097, -0.057, 0.066, ...
-0.037, 0.142, 0.17, 0.048, 0.042, -0.011] * x(:);
I think this is easier to ready.
Categorie
Scopri di più su Matrix Indexing 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!