Search code examples
matlabwindows-subsystem-for-linux

Why can't MATLAB find a script that is on MATLABPATH


I've just created a script file in MATLAB, but can not run it. The name of my script is getEnvFiles.m. When I first tried to run it, I got the following result:

>> getEnvFiles
'getEnvFiles' is not found in the current folder or on the MATLAB path, but exists in:
    \\wsl$\ubuntu\home\me

Change the MATLAB current folder or add its folder to the MATLAB path.

So, I added this directory (which is actually the current directory) to the search path, but still got the same result:

>> addpath('\\wsl$\ubuntu\home\me')
>> getEnvFiles
'getEnvFiles' is not found in the current folder or on the MATLAB path, but exists in:
    \\wsl$\ubuntu\home\me

Change the MATLAB current folder or add its folder to the MATLAB path.

When I check the path, it looks like this directory is on the path:

>> path

        MATLABPATH

    \\wsl$\ubuntu\home\me

I can further verify that this directory is my present directory:

>> pwd

ans =

    '\\wsl$\ubuntu\home\me'

and that getEnvFiles.m is in this directory:

>> ls

.                          .emacs.d                   HarborData                 
..                         .emacs~                    RawHarborData              
.bash_history              .landscape                 at                         
.bash_logout               .motd_shown                getEnvFiles.m              
.bashrc                    .profile                   test.m                     
.bashrc~                   .sudo_as_admin_successful  
.emacs   

Is the issue that I'm using wsl (Windows Subsystem for Linux), or do I have some other misunderstanding?


Solution

  • Type rehash and then try running your script again. Even though you have added the new directory to your path, you need to update the path cache so that it knows about the new scripts it can see.