>> TourLength Not enough input arguments. Error in TourLength (line 3) n=numel(tour);

조회 수: 1 (최근 30일)
Wonseh
Wonseh 2022년 12월 2일
답변: Joseph 2023년 3월 16일
function L=TourLength(tour,model)
n=numel(tour);
tour=[tour tour(1)];
L=0;
for k=1:n
i=tour(k);
j=tour(k+1);
L=L+model.d(i,j);
end
end
  댓글 수: 2
Askic V
Askic V 2022년 12월 2일
Most probably you're trying to execute this as a Matlab script and not as a function. You need to properly call the function from command window or from the other script (or function) with specified arguments.

댓글을 달려면 로그인하십시오.

답변 (2개)

Gokul Nath S J
Gokul Nath S J 2022년 12월 7일
Hi Wonseh,
As per my understanding, you have created a function TourLength containing 2 input arguments. If you directly run this function in MATLAB by clicking the run button, you will encounter a similar error. For example, if executing from the command window you might need to enter the following command
TourLength(input_argument1, input_argument2);
Also, you might need to ensure that the arguments passed as the function parameters are appropriate. Inappropriate arguments can also lead to numel error.

Joseph
Joseph 2023년 3월 16일
good

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by