嵌套文本扫描语句
以下两个语句从输入文件 (fid
) 中读取第一行,并将该行解析为由空格分隔的字符串。
a = textscan(fid,'%s',1,'Delimiter','\n');
b = textscan(a{1}{1},'%s');
我想知道此操作是否可以在单个语句中完成,其形式类似于以下内容(在语法上无效)。
b = textscan(textscan(fid,'%s',1,'Delimiter','\n'),'%s');
谢谢。
The following two statements read the first line from an input file (fid
) and parse said line into strings delimited by whitespace.
a = textscan(fid,'%s',1,'Delimiter','\n');
b = textscan(a{1}{1},'%s');
I would like to know if this action can be accomplished in a single statement, having a form similar to the following (which is syntactically invalid).
b = textscan(textscan(fid,'%s',1,'Delimiter','\n'),'%s');
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相反,
您可以使用
That 将以字符串形式返回 fid 中的下一行(末尾的换行符被删除)。然后,您可以将该行拆分为空格分隔的块,如下所示:
组合:
请注意,这并不 100% 等同于您的代码,因为使用
textscan
添加了另一个单元格层(代表单元格中的不同行)文件)。不过,这不是问题,如果您需要额外的细胞层,只需使用即可。
Instead of
you can use
That will return the next line in
fid
as a string (the newline character at the end is stripped). You can then split that line into white-space separated chunks as follows:Combined:
Note that this is not 100% equivalent to your code, since using
textscan
adds another cell-layer (representing different lines in the file). That's not a problem, though, simply useif you need that extra cell-layer.