Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

textscan

0 views
Skip to first unread message

Roland

unread,
Sep 2, 2010, 3:34:04 PM9/2/10
to
Hello!

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

Walter Roberson

unread,
Sep 2, 2010, 3:46:58 PM9/2/10
to

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.

exosceleton

unread,
Sep 2, 2010, 3:49:19 PM9/2/10
to
How about this one:

number=textscan(strrep('(1,500)',',',''),'(%f)')

Roland

unread,
Sep 2, 2010, 3:58:19 PM9/2/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <i5ov2b$p5i$1...@canopus.cc.umanitoba.ca>...

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!

Roland

unread,
Sep 2, 2010, 4:00:24 PM9/2/10
to
"exosceleton" <exosc...@hotmail.com> wrote in message <i5ov3v$9r7$1...@fred.mathworks.com>...

> How about this one:
>
> number=textscan(strrep('(1,500)',',',''),'(%f)')

thanks exosceleton, thats perfect!

Walter Roberson

unread,
Sep 2, 2010, 4:28:55 PM9/2/10
to

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.

0 new messages