The problem is with new "string" type in Matlab and "Starting in R2017a, you can create strings using double quotes" --manual.
Thus length("CODY") = 1 vs strlength("CODY") = 4
and string(["aa" "bb" "cc"]) is 1x3 string array which is not correct answer. (check strjoin function)

But zero is not sorted in this solution. You should get same answer for input x = 691 and 6910. (And then no need for abs())
1) 9610-0169=9441
2) 9441-1449=7992
3) 9972-2799=7173
4) 7731-1377=6354
5) 6543-3456=3087
6) 8730-0378=8352
7) 8532-2358=6174