MATLAB: How to select specific letters in a name How could I get MatLab to select specific letters from a name and count them. Say I wanted to select all the s' in (Savannah's new snowmobile). There are 3 s' in it, how would I select and add them together? Best Answer >> str = 'Savannah''s new snowmobile';Method one: logical comparison:>> nnz('s'==lower(str))ans = 3Method two: regexpi:>> numel(regexpi(str,'s'))ans = 3Method three: strfind:>> numel(strfind(lower(str),'s'))ans = 3 Related SolutionsMATLAB: How to count repeated character in string ? str='aaaaddccccfeeee'[ii,jj,kk]=unique(str)freq=histc(kk,1:numel(ii))c=regexp(ii,'.','match')'out=[c num2cell(freq)] MATLAB: Number of times two numbers appear together >> A = [1,3,2,4,3,4,3,2,1,1,3,2,4,3,3,2];Method one: basic indexing and nnz:>> nnz(A(1:end-1)==1 & A(2:end)==2)ans = 0>> nnz(A(1:end-1)==1 & A(2:end)==3)ans = 2>> nnz(A(1:end-1)==1 & A(2:end)==4)ans = 0Method two: strfind:>> nnz(strfind(char(A),char([1,2])))ans = 0>> nnz(strfind(char(A),char([1,3])))ans = 2>> nnz(strfind(char(A),char([1,4])))ans = 0 Related QuestionHow to read a string character by characterSorting a vector by another vector with same termsHow to find a first letter in a stringUnique values in an array, with specific digits
Best Answer