Error "std::exception" with function textscan in Matlab 2013b
4 次查看(过去 30 天)
显示 更早的评论
Hi everybody, i have a file Text.txt with following sepecified content:
!typ truck,bus,car,motor,bicycle
!end typ
!allowed car,motor,bicycle
!end allowed
I want to get the string "car,motor,bicycle" from the row "!allowed car,motor,bicycle". So I did these in MATLAB 2012b:
io_contents = fullfile( 'Text.txt'); % open Textfile
Text = fileread( io_contents ); % read the content of io_contents
Rowbegin = strfind(Text,'!allowed'); find the beginn of the row in Text
Rowend = strfind(Text,'!end allowed')-3 ; find the end of the row in Text
Row = Text(Rowbegin:Rowend)
String = textscan(Row,'!allowed%s ');
String = String{1}{1}
it should work in Matlab 2012b,but in matlab 2013b it shows this message:
Caught "std::exception" Exception message is: invalid string position
at line 6 , where textscan used is.
Could you tell me the reason, and how could I solve it. Is the an alternativ functioini for the function textscan ? Thanks a lot
0 个评论
回答(1 个)
Walter Roberson
2014-1-1
It would make more sense to use regexp() for that purpose.
String = regexp(Row, '(?:^!allowed\s+)\S+', 'match');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!