fitcsvm() is not designed to train directly on 28x28 images. You need to extract feature vectors for each image. After feature extraction, you will have a dataset with size 2000xN, where N is the number of features for each image. Let's say X is this new extracted feature set of size 2000xN, and Y is your labeledData of size 2000x1.
Now, before training fitcsvm(), you need to use cvpartition() (or something similar, maybe your custom method) to divide both the features and the labels data into training and testing dataset. Then, you can use
SVMStruct =fitcsvm(trainingData,trainingLabelData)
As far as I know, you can use Convolutional Neural Networks (CNN) to train directly on images.
Minor issues with your code:
- in both loops, you are assigning the labelData the same value.
- you don't really need those loops: labelData(1:1000) = 0; labelData(1001:2000) = 1;
Hope this helps.