Not enogh in input arguments error in matlab code. how to solve?

function [ alpha ] = solve_alpha( size_data, desired, K, C )
%SOLVE_ALPHA
% Calculates the value of alpha for SVM
% size_data : Number of samples
% desired : Label vector
% K : Kernel matrix
% C : 10^6 for hard margin, less otherwise
% Returns :
% alpha : alpha values given by the optimisation problem
%%Initialize inputs for quadprog
H = zeros(size_data, size_data);
for i = 1:size_data
for j = 1:size_data
H(i,j) = desired(i) * desired(j) * K(i,j);
end
end
f = -ones(desired, 1);
Aeq = desired';
Beq = 0;
lb = zeros(size_data, 1);
ub = ones(size_data, 1) * C;
x0 = [];
options = optimset('LargeScale', 'off', 'MaxIter', 1000);
A = [];
b = [];
%%Call quadprog
[ alpha, ~, ~ ] = quadprog(H, f, A, b, Aeq, Beq, ...
lb, ub, x0, options);
end

6 Comments

You've copy/pasted the code of a function. and that's it. No explanation as to what the problem is. Is there a problem with the function? If so, what line is causing the problem and what arguments did you give to the function? Or perhaps the problem is with the way you call the function, but you haven't said anything about that either.
@cute smile: please show us the complete error message. This means all of the red text.
Error using solve_alpha (line 14)
Not enough input arguments.
H = zeros(size_data, size_data);%line 14
Are you calling the function with all the arguments?
@cute smile: I don't see %line 14 anywhere in your code: are you sure that that is really the code for that error message?
  • Please show us exactly how you are calling solve_alpha.
  • Please show us the complete output of this command:
which solve_alpha -all

Sign in to comment.

Answers (1)

Paolo is correct, there can be only one reason to get:
Error using solve_alpha (line 14)
Not enough input arguments.
H = zeros(size_data, size_data);%line 14
and that is because you're not calling solve_alpha with all the arguments, despite what you say. In fact, since size_data is the first input argument, if you get the error that means you haven't passed any argument at all.
The function must be called with all 4 arguments, e.g.:
result = solve_alpha(5, 1:5, magic(5), 10^6); %completely meaningless inputs here
While we're at it, you can replace the whole of
H = zeros(size_data, size_data);
for i = 1:size_data
for j = 1:size_data
H(i,j) = desired(i) * desired(j) * K(i,j);
end
end
by
H = desired .* desired.' .* K;
if on R2016b or later, or
H = bsxfun(@times, desired, desired.') .* K;
for earlier versions. You'll still need to provide all four inputs.
edit: Oh and I've just spotted this:
f = -ones(desired, 1);
Unless the built-in ones has been shadowed (an extremely bad idea), this will throw an error. I have no idea what the intent is here, so can't say what the correct code should be.

2 Comments

@Guillaume using
H = desired .* desired.' .* K;
still error in code, actually i'm calculatin aplha for hard margin SVM. & this error is common in my all functions
My recommended modification is completely unrelated to the error you get. It's just simpler code.
As I said, The function must be called with all 4 input arguments. Until you do, you'll keep getting errors.
As I've also said in my edit, with this particular function, once you've called it correctly, you'll get a completely different error on
f = -ones(desired, 1);
No idea what the intent of that line is. It's nonsense at the moment.

Sign in to comment.

Tags

Asked:

on 25 May 2018

Commented:

on 25 May 2018

Community Treasure Hunt

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

Start Hunting!