classf = @(xtrain,ytrain,xtest,ytest) sum(classify(ytest,xtest,train(ytrain,xtrain)) ~= ytest);
Since, you want to use a neural network, you should be using the classify and train functions from the Deep Learning Toolbox. The train function outputs the trained shallow neural network. The classify function returns the predicted labels and scores (if required).
For more information on how to use these functions, you can refer to the following links:
Also, since you want to use patternnet, one possible modification which can be made to your code is:
classf = @(xtrain, ytrain, xtest, ytest)
sum(classify(train(patternnet(50), xtrain, ytrain), xtest) ~= ytest);
You can also use the trainNetwork function which allows you to model your own deep neural networks or load any pre-trained network. For more information, you can refer to the following link: