MATLAB: Replace character in string/cell with the character above it

replace

String/cell example: –> real string/cell is very long
a= { 'a' ; 'b' ; 'c' ; 'b'}
Wanted outcome:
a_new= { 'a' ; 'a' ; 'c' ; 'c'}

Best Answer

The general rule is not perfectly clear to me, from your small example. Do you mean that you want the even-numbered elements to be replaced? If so, then
anew = a;
a(2:2:end) = a(1:2:end-1);
If not, maybe you could explain in a little more detail.