i want textscan to recognise my string '(1,500)' as the number 1500
i dont really know how to get rid of the brackets and the comma
number=textscan('(1,500)',??)
any ideas?
Roland
Sorry, Matlab does not support any way to do that in textscan() in a single
step. If you have a file that uses comma as the decimal grouping character
then it is recommended that you pre-process the file to remove the commas
before attempting to parse the file.
number=textscan(strrep('(1,500)',',',''),'(%f)')
sometimes, telling that one function is not capable of doing something also leads to the solution, i use now:
oldstring=('1,500')
modstring=strrep(oldstring, ',' , '')
number=str2num(modstring)
thanks!
thanks exosceleton, thats perfect!
str2num() uses eval() to evaluate the string. That is relatively slow and is a
security risk. str2double() or one of the formatted input routines such as
sscanf() or textscan() are safer and potentially much faster.