Hi Tu Nguyen,
I understand that you are trying to classify ECG data using “fitcknn” and “fitcsvm” inbuilt function.
To classify ECG data using the built-in functions “fitcknn” and “fitcsvm”, you can refer to the provided code snippet:
% Load the data into the MATLAB workspace from the file
a = load("ecg.csv")
% Divide the data into Training data and Testing Data. You can try %different algorithms for data division
cv = cvpartition(size(a,1),'HoldOut',0.3);
idx = cv.test;
% Separate the training and test data
dataTrain = a(~idx,:);
dataTest = a(idx,:);
% Separate the input data and output data from the training data
dataTrainX = dataTrain(:,(1:end-1));
dataTrainY = dataTrain(:,end);
% Train the Model using the built-in functions
Mdl = fitcknn(dataTrainX, dataTrainY);
Md2 = fitcsvm(dataTrainX, dataTrainY);
For more information on “fitcknn” function, you can refer to the below Mathworks documentation link: -
For more information on “‘fitcsvm” function, you can refer to the below Mathworks documentation link: -
I hope this helps!