MATLAB: How to take out a specific row out of matrix

row

Hello I have this matrix :
a = [john 2016;john 2015;mike 2016;leo 2018]
I only need information from 2016 in second column, like:
n = [john 2016;mike 2016]
I am using this code but it does not work. any help ? Thank you !
b = [2016];
n = a(ismember(a(:,2),b),:);

Best Answer

Attach your workbook. This can probably be done with tables:
t = readtable(filename);
rowsToExtract = t{:, 2} == 2016
t2016 = t(rowsToExtract, :)