MATLAB: How to create a for loop to count letters in a sequence

loopsMATLAB

i have the following sequence
a = b c d b c d e c c d b c b e e
i want to create a for loop to identify the number of b’s and c’s in the sequence?
help please

Best Answer

No loops needed:
a = 'b c d b c d e c c d b c b e e'
no_of_bs=sum(ismember(a,'b'))
no_of_cs=sum(ismember(a,'c'))