Why matlab does not understand * in the names of files?

被刻印的时光 ゝ 提交于 2019-12-10 18:08:08

问题


I tried to use:

dir('dirname\*')

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

dir('dirname\m*')

Does anybody know why?


回答1:


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/*')

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.

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




回答2:


Try to provide the full path, like dir('c:\dirname*.m'), and make sure the folder 'dirname' exists.




回答3:


What is your OS ? Here on Windows, the first line works well. However, the "*" is maybe considered by Matlab as a literal "*". What happens with dir('dirname/*') ?



来源:https://stackoverflow.com/questions/5337846/why-matlab-does-not-understand-in-the-names-of-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!