MATLAB: How to find the number of items that start with the letter s in a matrix

matrix manipulation

I have a matrix with city names in the first column and numbers in the second column, how do find all the cities that start with the letter s.

Best Answer

One thing is sure, you do not have "a matrix with city names in the first column and numbers in the second column" since matrices do not allow you to mix data types. You may have a cell array or a table or something else. I'm going to assume a cell array
In version of matlab < R2016b, you can use strncmp (or the case insensitive version strncmpi):
strncmp(yourcellarray(:, 1), 's', 1)
In R2016b or latter, startsWith is even easier to use:
startsWith(yourcellarray(:, 1), 's')