MATLAB: Split string into 3 letter each

split string into 3 letter each

if have a
str = 'AGTCTGTCTTTG';
i wanted to split it into 3 letters each
AGT CTG TCT TTG
and replace
AGT with J
CTG with U
TCT with N
TTG with D
how to do it… please do reply….
i did as below
str = 'AGTCTGTCTTTG';
j = 1;
for k = 1: 3: length(str)
word(j) = str(k : k +3)
j = j+1;
end
but i get error as
??? Subscripted assignment dimension mismatch.
Error in ==> Untitled2 at 4
word(j) = str(k : k +3)
please do reply….

Best Answer

str ='AGTCTGTCTTTG';
a=cellstr(reshape(str,3,[])')
What is the aim of the replacement ? you can create
v={'J','U','N','D'}