我有一个包含以下指定内容的文件 Text.txt:
!typ truck,bus,car,motor,bicycle
!end typ
!allowed car,motor,bicycle
!end allowed
我想从“!allowed car,motor,bicycle”行中获取字符串“car,motor,bicycle”。所以我在 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')-4 ; %find the end of the row in Text
Row = Text(Rowbegin:Rowend)
String = textscan(Row,'!allowed%s ');
String = String{1}{1}
它应该在 Matlab 2012b 中工作,但在 matlab 2013b 中显示此消息:
Caught "std::exception" Exception message is: invalid string position
在第 6 行,使用的 TEXTSCAN 是。
你能告诉我原因吗,我该如何解决。是函数 textscan 的替代函数吗?非常感谢