为什么Matlab在文件名中看不懂*? [英] Why matlab does not understand * in the names of files?

查看:91
本文介绍了为什么Matlab在文件名中看不懂*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用:

dir('dirname\*')

,但它不起作用.在我开始使用后,它开始工作:

and it did not work. It started to work after I started to use:

dir('dirname\m*')

有人知道为什么吗?

推荐答案

Matlab可以理解通配符*,但是您以不走运的方式尝试遵守Windows cmd路径约定,因此输入了字符串\*,即文字星号(由于转义的反斜杠).

Matlab does understand wildcards *, but in the way you unluckiliy tried to adhere to Windows cmd path conventions, you entered the string \*, which is a literal asterisk (due to the escaping backslash).

一种变通方法或在所有平台上指定路径的首选方法是使用斜杠/作为目录分隔符.

A workaround, or the preferred way to specify paths on all platforms, is using a forward slash / as a directory seperator.

dir('dirname/*')

这也解释了为什么在反斜杠后添加m可以解决"该问题;星号不再是文字星号,而是允许解释为通配符.

This also explains why adding the m after the backslash "fixed" the issue; the asterisk was no longer a literal asterisk, but allowed to be interpreted as a wildcard character.

文档明确表示允许通配符并且可以使用通配符符合预期(请参见上面的说明).

Documentation explicitely says the wildcard character is allowed and works as expected (see my explanation above).

这篇关于为什么Matlab在文件名中看不懂*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆