Not enough input arguments error
Show older comments
Hello. I'm trying to write a function that receives a matrix and then finds the mininum value in each column and then returns a vector of column minimums. The code is below. I'm getting not enough input error and I'm not sure what is wrong with the code. I'd greatly appreciate it if someone could help me.
function answer = matlabbooktest(matrix)
[rows, columns] = size(matrix);
answer=zeros(1,columns);
vector=zeros(1,columns);
for i=1:columns
for j=1:rows
vector(1,j)=matrix(j,i);
end
answer(1,i)=min(vector);
end
disp(answer)
6 Comments
dpb
on 24 Nov 2018
We'd have to see how you called it to know, but it would appear if that's the message you tried to reference the function matlabbooktest without an argument.
As aside, is it prescribed you you solve the problem? You can do the requested operation in one line if you're allowed to use builtin min -- if you're supposed to find the minima by not using the builtin function, then you didn't do that...would be interesting here to see the actual question wording.
John Tucker
on 24 Nov 2018
Edited: John Tucker
on 24 Nov 2018
Elias Gule
on 24 Nov 2018
I guess you ran it by clicking on the run button... that's equivalent to calling the function. Now as you click the run button - a particular function gets executed (that function is called a 'callback' in Matlab lingo); it is that function that actually calls your function; and since your function requires an input which that button's callback is not supplying (of course), that is why you're getting an error.
dpb
on 24 Nov 2018
"Just running" a function is the same as calling it -- it must have an input argument; matrix is a dummy variable that is only known inside the function -- it gains a value only by association with the actual argument passed when the function is called.
John Tucker
on 24 Nov 2018
dpb
on 25 Nov 2018
But you don't need any other function unless the requirement is something more than just returning the row vector of column minima--
>> m=randi(10,4) % a sample dataset
ans =
3 1 4 1
3 5 9 5
10 9 3 6
9 5 6 6
>> min(ans) % min function does column minima by default
ans =
3 1 3 1
>> min(m,[],2) % to get row minima instead...
ans =
1
3
3
5
>>
Hence my confusion over the purpose of writing another function for the particular exercise.
One can return the locations as well with the optional additional return value. For column minima, it's the row (first occurrence in case of ties) or column if row minima are returned. The other location is inferred, of course.
Answers (0)
Categories
Find more on Analysis of Variance and Covariance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!