How to calculate Precision and Recall using confusion matrix in Matlab?
if yHat are your predictions and yval are your y true then

tp = sum((yHaT == 1) &amp; (yval == 1));
fp = sum((yHaT == 1) &amp; (yval == 0));
fn = sum((yHaT == 0) &amp; (yval == 1));

precision = tp / (tp + fp);
recall = tp / (tp + fn);
F1 = (2 * precision * recall) / (precision + recall);