MATLAB: ‘ The length of GROUP must equal the number of rows in TRAINING.’,how can i solve this issue…

classificationdigital signal processingMATLABsignal processingStatistics and Machine Learning Toolbox

Hi, I am new to the matlab coding.when iam using linear classifier to classify the test and train signal it shows' The length of GROUP must equal the number of rows in TRAINING.',and the code i have used is given below,
a=ones([1060,1]);
b=zeros([1060,1]);
c=cat(1,a,b);
class=classify(test,train,c,'linear');
SVMStruct=svmtrain(train,c);
class=svmclassify(SVMStruct,test,'Showplot',true);
class = knnclassify(test,train,c,1);
and
>>size(test)
ans =
2 6354
size(train)
ans =
2 9540
>> size(c)
ans =
2120 1
how can i solve this problem…?
Any response would be greatly appreciated. Thanks in advance.

Best Answer

I suggest you carefully read the documentation for classify, and really try to understand what each input represents.
The main conceptual thing to understand is that the third argument, group (your variable c), should have the same number of rows as the second argument, training, (your variable train). The reason is that you are telling classify which group that each row of training belongs to. For example,
training = [1 2;
6 5;
4 4;
1 1];
group = [1;
2;
2;
1];
would be telling MATLAB that the first and last row of training are in group 1, and the other two rows are in group 2.