String value and sequently representation
2 views (last 30 days)
Lets say i have string
and I want something like this
so that it would give me like this result:
and so on....but this code
is not working. Could u help me please.
Geoff Hayes on 27 May 2014
Edited: Geoff Hayes on 27 May 2014
M is a matrix with a single row, so the code cannot access anything but that first row. As soon as i is greater than 1, then M(i,i+1) will fail with an index out of bounds exception. If you just want to get the pairs, then try something like:
for i=1:2:length(M) % since we are interested in the odd indices only
str = M(i:i+1); % get the two neighbouring characters
If you want to print out something like you have above, then just replace the middle line with
If you are trying to save the values at each iteration to a variable named Li then that gets a little more challenging (is it even necessary?).