Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“错误”;标准::例外情况“;在Matlab2013b中使用函数textscan_Matlab_Textscan - Fatal编程技术网

“错误”;标准::例外情况“;在Matlab2013b中使用函数textscan

“错误”;标准::例外情况“;在Matlab2013b中使用函数textscan,matlab,textscan,Matlab,Textscan,我有一个文件Text.txt,其中包含以下单独指定的内容: !typ truck,bus,car,motor,bicycle !end typ !allowed car,motor,bicycle !end allowed 我想从这一行中得到字符串“汽车、马达、自行车”!允许的汽车、马达、自行车。所以我在MATLAB 2012b中做了这些: io_contents = fullfile( 'Text.txt'); % open Textfile Text = fileread( i

我有一个文件Text.txt,其中包含以下单独指定的内容:

 !typ truck,bus,car,motor,bicycle 
 !end typ 
 !allowed car,motor,bicycle
 !end allowed
我想从这一行中得到字符串“汽车、马达、自行车”!允许的汽车、马达、自行车。所以我在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是否为可选函数?非常感谢

尽管我并不确信这与2013b版本有关,但这里有一个替代解决方案

textscan
行替换为:

strrep(Row,'!allowed ','')
如果您想做更高级的事情,您可以研究正则表达式,但是对于匹配字符串中的单词,这通常是最简单的方法。作为奖励,它也应该相当有效


如果不需要
的中间结果,也可以跳过步骤。 在这种情况下,请使用:

String = Text(Rowbegin+9:Rowend) 

String=textscan(行,!允许的%s')
的预期用途是什么?如果只是为了删除
!允许
行的开头
,为什么不搜索第二个
并删除之前的所有内容?无法复制错误。在R2013a上,您的代码生成
行=
!允许的
!汽车、摩托车、自行车
字符串=
''
。这到底是什么奇怪的文本文件格式?:-)如果出现错误,请使用
dbstop运行代码,并查看发生错误时
行的值。@LuisMendo我想从行“!allowed car,motor,bicycle”中获取字符串“car,motor,bicycle”,正如您所说,它只是从行中删除组“!allowed”。@A.Dona抱歉,我的课文有个错误。我纠正了它。每行开头都会有一个“!”。