MATLAB Answers


I need to locate an installed program in MacOS using Matlab, how can I do that?

Asked by Mårten Cronander on 22 Aug 2019
Latest activity Commented on by Mårten Cronander on 28 Aug 2019
I need to locate an installed program in MacOS using Matlab, how can I do that?
My Matlab code needs to make sure a certain 3rd party program is installed on the computer running the matlab code.
I have a way to do it on Windows ('WHERE /F /R "C:\Users\...'), but how can I do it in Matlab?


Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 22 Aug 2019
 Accepted Answer

Mårten - you could try something like
[status, path] = system('find ~/Documents/geoff -name myFile.m')
The above would search in all directories (and subdirectories) for a file named myFile.m. If the file can be found, then the path would be set with the location of that file.


It can pay to first use system() of a 'which' command. which is a shell built in that looks on the Unix path.
In theory you could ask Spotlight about the file, but in my experience it is common for Spotlight to not find what I am looking for.
The unix find command can be slow, especially if you do not confine it to a single mount point (drive) and very slow if you somehow get it searching a Time machine volume.
Sometimes it is best to just try the most common locations like /bin and /usr/bin and /usr/local/bin and look in /opt where Homebrew tends to install, and look in the user's ~/Applications and similar, and look at environment variables for an appropriate name... And if it is not in those places then either prompt the user or force a configuration step be done. Looking through all the drives can take hours (I have more than 10TB these days.)
Thank you, that helped me.
Best regards

Sign in to comment.