简体   繁体   中英

What is the Matlab install directory on 64bit or how to get it in Python?

I have Matlab2013b on my system at :

C:\\Program Files\\MATLAB\\R2013b\\bin

I am writing Python script that searches for Matlab.exe first at this location and then at location for 64 bit. The Python script will be run on a server which might have a 64 bit instead of 32 bit. So, I need to search for both locations.
Since I don't have 64 bit version on my machine, I don't know the location.

I am speculating it will be:

C:\\Program Files (x86)\\MATLAB\\R2013b\\bin

But can anybody confirm that?
Thanks
sedy

You can read out the environment variable PATH (I'd say it's quite sure MATLAB it's included) and use some string operations to get the Matlab path:

import os
path = os.environ.get('path')
pathlist = path.split(';')
matlabpath = [s for s in pathlist if all(x in s for x in ['MATLAB','R','bin'])]
print(matlabpath)

this way you don't need to speculate what I would consider a generally bad programming practice.


In my case there is also an toolbox polyspace on the same path, you need to exclude that:

matlabpath = [s for s in pathlist if all(x in s for x in ['MATLAB','R','bin']) and not 'polyspace' in s]

There may be other toolboxes writing itself into path - it could be cumbersome to exclude all of them, so the easiest would be to just return the shortest of all Matlab related paths:

import os
path = os.environ.get('path')
pathlist = path.split(';')
matlabpath = min([s for s in pathlist if 'MATLAB' in s], key=len) 
print(matlabpath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM