Octave keyboard input function to filter concatenated string and integer? -
if write 12wkd3, how choose/filter 123 integer in octave?
example in octave:
a = input("a?\n")   a?   12wkd3    = 123  while 12wkd3 user keyboard input , a = 123 expected answer.
assuming general form you're looking taking arbitrary string user input, removing non-numeric, , storing result integer:
a = input("a? /n",'s'); = int32(str2num(a(isdigit(a))));  example output:
a? 324bhtk.p89u34 = 3248934 to clarify what's written above:
- in input statement, - 's'argument causes answer stored string, otherwise it's evaluated octave first. inputs produce errors, others may interpreted functions or variables.
- isdigit(a)produces logical array of values- a1 character 0-9 number, , 0 otherwise.- isdigit('a1 3 b.') = [0 1 0 1 0 0 0]
- a(isdigit(a)) produce substring using values corresponding 1 in logical array above. - a(isdigit(a)) = 13
- that still returns string, need convert number using - str2num(). that, however, outputs double precision number. integer can use- int32()
Comments
Post a Comment