Matlab feature selection
func = @(xtrain, ytrain, xtest, ytest) sum(ytest ~= predict(Md1,xtest));


The function "func" is called by sequentialfs, which does not pass "Md1" to the "predict" function. Therefore, Md1 is unknown to that "cost" function. You should include "Md1=fitcdiscr(xtrain,ytrain);" within your "func" function.  

Beside, "sequentialfs" does a 10-fold CV. Why are you trying to pass only 299 samples instead of all 300?