Reputation: 43
For a project, I'm trying to use matlab to call a function in another .m file. However, it says 'Not enough input arguments', even though I do pass what I am fairly certain is enough input arguments.
In eval_square.m:
function f = eval_square(x)
% fitness function of the magic square
%
% Parameters
% ----------
% x : array, the solution vector that represents a magic square.
% By default, the solution vector is converted to a magic square
% columnwisely.
% Output
% ----------
% f : double, the error value of the input solution vector.
% the mean squared error (MSE) of all each row, column and
% diagonal sum to the magic constant is computed
%
n = sqrt(length(x));
%More stuff, but error occurs at this line.
in MYNAME_sa.m:
function [xopt, fopt] = MYNAME_sa(dim, eval_budget, fitness_func)
%Stuff
if dim == 2
len = 12^2; % length of the solution vector, shoud be 12^2
% when dim == 2
elseif dim == 3
len = 7^3; % length of the solution vector, shoud be 7^3 when
% dim == 3
end
%Stuff
s = randperm(len)
f = fitness_func(s)
%More stuff.
It's supposed to evaluate the random permutation of length 12^2 as a magic square, to see how close it is to optimum (i.e. how close it is to being an actual magic square) and in theory the same for a magic cube (eval_cube), but the same error occurs.
The error in question:
>> MYNAME_sa(2, 10000, eval_square)
Error using eval_square (line 18)
Not enough input arguments.
Note that line 18 is n = sqrt(length(x));
It doesn't matter if I hardcode eval_square into the function - it seems to understand that I want to call eval_square just fine, but it just doesn't pass s or something? And I don't understand why. I tried hardcoding n to 12 as well, but that doesn't work either, the error pops up when I'm trying to actually use x then. Changing fitness_func to @fitness_func also changes nothing. So my question is, why does this happen and how do I fix it?
Upvotes: 2
Views: 466