I was looking for a way to separate the digits of an array in Matlab ie if A = 1024 , then I would like it to be A = [1, 0, 2, 4] .
I searched the net and found this code (also published in the header):
sprintf('%d',A) - '0'
which transformed [1024] → [1, 0, 2, 4] .
This solved my problem, but I did not understand it, especially the part - '0' . can someone explain how this works?
Also, if I write sprintf('%d',A) + '0' (for A = [1024] ) in the MATLAB command window, then it showed the following:
97 96 98 100
This puzzled me even more, can anyone explain this?
source share