필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Ali Mania
Ali Mania 2013년 12월 20일
답변: Walter Roberson 2014년 1월 1일
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

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by