Error: Not enough input argument (line 6)

Why do I get this error message when running following script?
function outtype = findargtype (inputarg)
% findargtype determines whether the input
% argument is a scalar,vector, or matrix
% format of call: findargtype(inputArgument)
% Returns a string
[r c] = size (inputarg) ;
if r== 1 && c== 1
outtype='scalar';
elseif r== 1 || c== 1
outtype='vector';
else
outtype='matrix';
end
end

댓글 수: 2

Star Strider
Star Strider 2012년 8월 23일
How are you calling your function findargtype from your main script? What are you giving it for inputarg as an argument?
Your code does not react consistently to empty inputs. The [] construct is 0 by 0 and so would show up as 'matrix' in your tests, but zeros(0,1) would show up as vector.
Please also try this test:
[r c] = size(zeros(0,1,2))
and
[r c] = size(zeros(1,0,2))
size() does not do what you think it does.

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

 채택된 답변

Matt Fig
Matt Fig 2012년 8월 23일

1 개 추천

The error is not in the function, but in the way you called it. You called it with no input arguments.

댓글 수: 2

John
John 2012년 8월 24일
Well the name of the function in my case is the same as the name of the M-file i.e. findargtype.m How would you else call the function so that it includes the input arguments? Sorry if I am taking your time
You call it the same way you call any function that takes one argument. Pass the argument...
findargtype(pi)
You may need to read:
doc function

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by