I want to take user input entered as an integer, for example (45697)
, and store the first two digits in an array, vector, or something else such as ( 4 5
You can do it easily using conversions to/from strings:
>> x = 45697; % or whatever positive value
>> str = num2str(x);
>> y = [str2num(str(1)) str2num(str(2))]
y =
4 5
This assumes that the number x
is positive (if it were negative the first character would not be a digit). That seems to be the case, since according to your comments it represents an electrical resistance.