Error "std::exception" with function textscan in Matlab 2013b

6 vues (au cours des 30 derniers jours)
Ali Mania
Ali Mania le 20 Déc 2013
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

Réponses (1)

Walter Roberson
Walter Roberson le 1 Jan 2014
It would make more sense to use regexp() for that purpose.
String = regexp(Row, '(?:^!allowed\s+)\S+', 'match');

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by