user3657408
user3657408

Reputation: 99

Finding file in MATLAB's path

In MATLAB, I have a file name (for example 'file name') as a string assigned to a variable fname. I want to find where in the MATLAB path this file can be found, if anywhere. which(fname) just tells me that fname is a variable whereas which('file name') gives me the path info. How can I do it with the name in a variable?

Upvotes: 0

Views: 107

Answers (1)

rayryeng
rayryeng

Reputation: 104565

which should also be able to take in string variables. I'm not sure why you're just getting the variable itself. Here's an example (on Mac OS X 10.9.3 using MATLAB R2013a):

fname = 'imfilter.m';
loc = which(fname)

loc =

/Applications/MATLAB_R2013a.app/toolbox/images/images/imfilter.m

However, if you encapsulate the variable as a string, it will spit out that it's a variable:

loc = which('fname')

loc = 

variable

Upvotes: 1

Related Questions