What is the usual way in MATLAB to read an integer into an array, digit by digit?
I'm trying to split a four digit integer, 1234 into an array [1 2 3 4].
Here is a very easy way to do it for a single integer
s = num2str(1234)
for t=length(s):-1:1
result(t) = str2num(s(t));
end
The most compact way however, would be:
'1234'-'0'
'1' is exactly 1 higher than the character code of '0'. Try '0' + 0 to find out what the codes actually are.[12 23 34 41] for example.num2str(matrix) - '0' will sorta work, but will return a bunch of columns of -16 due to the spaces in the character matrix produced with num2strOr try this
result = str2num(num2str(1234)')'
1234a numeric value (like the body of the question suggests) or a string (char, like the title suggests)?