Johasua
Johasua

Reputation: 21

MATLAB using dir to search for specific filenames?

How can I use the dir command to look for files with certain parts? For example if I wanted all files in a directory that had 'random' in their names, how would I go about selecting only those files?

I know you can use the wildcard to look for certain strings, but is it possible to do it with variables? If name = random, then how would I look for files with 'random' in their names using just name?

Thanks

Upvotes: 2

Views: 162

Answers (2)

Reiff
Reiff

Reputation: 1

dir(['*' name '*'])

Also, make sure

name='random'

not

name=random

Upvotes: 0

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

Actually this is quite straightforward:

dir *random*

Quotes around random are optional.

Upvotes: 1

Related Questions