MATLAB Answers

0

How to find consecutive number of strings along with their starting position?

Asked by Md.Mobasshir Arshed on 10 Apr 2016
Latest activity Answered by Azzi Abdelmalek
on 10 Apr 2016
Assume i have cells containing values as
a,a,a,b,b,a,a,c,c,d,d
now how can i find number of a s along with the staring position. the answer would be like 3 starting at 0, and 2 starting at 5.
anyone please help...

  0 Comments

Sign in to comment.

1 Answer

Answer by Azzi Abdelmalek
on 10 Apr 2016

v={'a','a','a','b','b','a','a','c','c','d','d'}
idx=ismember(v,'a')
ii=strfind([ 0 idx],[0 1]);
jj=strfind([idx,0],[1 0]);
out=[ii'-1 (jj-ii)'+1]

  0 Comments

Sign in to comment.