Not enough input arguments error in function
이전 댓글 표시
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));
답변 (2개)
Alan Stevens
2021년 3월 13일
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
2021년 3월 13일
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!