I want to split up any given number (as a character) with "," in such a way that if there is a 2 or a 6, it and the next digit are taken as a pair and put a "," around them.
e.g. '1357320676222345' would become '13573,20,67,62,22,345'
my attempts just end up just putting a lot of ',' around the first pair that meets this condition
I realise it has to do with the fact the character length keeps increasing with each itteration, but I don't know how to get around this problem.
clearc = '1357320676222345'L = length(c)for i = 1:L if c(i) == '2' j = i c = insertBefore(c,i,',') c = insertAfter(c,i+2,',') continue end if c(i) == '6' j = i c = insertBefore(c,i,',') c = insertAfter(c,i+2,',') continue endend
Best Answer