Hi, I am very new to matlab and need some basic help.
function classifier = learnknn(k, d, m, Xtrain, Ytrain)
classifier = {k, d, m, Xtrain, Ytrain};
end
I get the error " Not enough input arguments. "
But, I cannot change the first line of this code. Only the body of the function can be modified.
Thank you.

7 Kommentare

Walter Roberson
Walter Roberson am 24 Okt. 2020
How are you invoking the function?
danielle sisserman
danielle sisserman am 24 Okt. 2020
I did not invoke it yet.
KSSV
KSSV am 24 Okt. 2020
Don't press the run button. Go to the folder where function is present....define the input variables and then call the function.
k = yourvalue ;
d = yourvalue ;
m = yourvalue ;
Xtrain = your data ;
Ytrain = your data ;
classifier = learnknn(k, d, m, Xtrain, Ytrain) ;
But what is the use of the function?
danielle sisserman
danielle sisserman am 26 Okt. 2020
Oh okay, thank you.
I just want the function to return a list containing the function's input arguments. Why? because I'm trying to implement the knn algorithm. The training part just saves the samples.
function varargin = learnknn(varargin)
is code that implements returning a cell containing the input arguments.
Thank you Walter.
so if I understand,
function classifier = learnknn(k, d, m, Xtrain, Ytrain)
is actually all I need? no
end
keyword?
and what if I wanted the classifier function to return a diferent datastructure than a cell?
for example, if I wanted to return a list object containing the input objects.
Thankyou.
Stephen23
Stephen23 am 5 Nov. 2020
"so if I understand, function classifier = learnknn(k, d, m, Xtrain, Ytrain) is actually all I need?"
No, the syntax that Walter Roberson showed replaces your entire function. It uses the special varargin variable:
"and what if I wanted the classifier function to return a diferent datastructure than a cell? for example, if I wanted to return a list object containing the input objects."
MATLAB does not have a "list" type:

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Gefragt:

am 24 Okt. 2020

Kommentiert:

am 5 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by