سؤال

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?

هل كانت مفيدة؟

المحلول

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).

نصائح أخرى

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top