user1956609
user1956609

Reputation: 2202

Error: Output Argument Not Assigned During Call

Here's my code for a k-nearest neighbors algorithm:

function [preds, distances, indices] = knnfull(HandTrain,HandTest)
    nn_value = 10; % how many nearest      
    inputs = HandTrain(:,2:end);
    Y = HandTrain(:,1); 
    [preds, distances, indices] = knn_alg(inputs, y, HandTest, nn_value);
end

function [preds, D, I] = knn_alg(train_inputs, train_y, test_inputs, nn_value)
    num_train_inputs = size(train_inputs,2);
    num_train_examples = size(train_inputs,1)
    num_test_inputs = size(test_inputs,2);
    num_test_examples = size(test_inputs,1)
    preds = zeros(size(test_inputs,1),1);
    [D,I] = pdist2(train_inputs,test_inputs,'euclidean','Smallest',nn_value);
    preds = mode(train_y(I'),2);
end

If you're asking why I have two separate functions, that's a good question. But regardless, I'm getting the errors:

Error in knnkaggle>knn_alg (line 16)
num_train_inputs = size(train_inputs,2);

Output argument "indices" (and maybe others) not assigned during call to
"C:...knn_alg".

Error in knnkaggle (line 10)
[preds, distances, indices] = knn_alg(inputs, y, HandTest, nn_value);

Can't figure out the issue.

Upvotes: 3

Views: 5938

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272517

It means that there are possible paths through your function which don't assign any value at all to the output argument.

Upvotes: 3

Related Questions