MATLAB: Function help – selects the even rows and columns and returns of matrix M and then puts them in a new matrix called even

matlab function

Hi,
I want to write a function in MATLAB that selects the even rows and columns and returns of matrix M and then puts them in a new matrix called even.
I am new to functions and I am not sure why I am getting the following error;
Not enough input arguments.
Error in even_index (line 2)
The code I am using is the following
function even = even_index(M)
even = M(2:2:end,2:2:end);
end
Thanks

Best Answer

You didn't pass any argument to the function when you called it -- hence there was nothing inside the function for M
M=rand(5);
even=even_index(M);
will work...