Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matlab Does Not Run Codes on Visual Studio Code #147

Open
seckinpolat opened this issue May 23, 2024 · 6 comments
Open

Matlab Does Not Run Codes on Visual Studio Code #147

seckinpolat opened this issue May 23, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@seckinpolat
Copy link

Describe the bug
I have Visual Studio Code Version: 1.89.1 with Matlab extension v1.2.2, I have Matlab R2024a.

Everything seems working but when I try to run a Matlab code in Visual Studio code, it gives me notification that "File is not found in the current folder or on the MATLAB path" after I click on "Add to Path" then I receive Unrecognized function or variable on terminal.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'my a.m file'
  2. Click on '.Run'
  3. Scroll down to 'Terminal'
  4. See error "Unrecognized function or variable a"

Expected behavior
I expected matlab code be running and generating plots and results.

Screenshots
image

Useful Information

  • OS Version: Sonoma14.5
  • VS Code Version: 1.89.1

Thank you for your help in advance.

@seckinpolat seckinpolat added the bug Something isn't working label May 23, 2024
@philipb314
Copy link
Member

Hello, I was unable to reproduce this on my side, so I had a few quick questions:

Can you please send me the full path of the file you are trying to run?

After you receive the error above can you try the following:
Can you send me the result from running ">> which('parse_file')" from the vs code MATLAB terminal?

And finally, if you manually add the file to the path by running ">> addpath('<directory where file resides')", does the run button work for that session?

Thanks!

@seckinpolat
Copy link
Author

I can share a simpler code.

my directory is /Users/seckinpolat/Documents/MATLAB

my code is trial.m

close all
clear all
a=1;
b=3;
plot(a,b)

After I run it

trial
Unrecognized function or variable 'trial'.

When I tried to write your on VS I received the following error

which ('trial')
'trial' not found.

When I run the same line on my Matlab command line

which('trial')
/Users/seckinpolat/Documents/MATLAB/trial.m

When I manually enter addpath('/Users/seckinpolat/Documents/MATLAB/trial.m')

I received this following error on VS >> addpath('/Users/seckinpolat/Documents/MATLAB/trial.m')
Warning: Name is nonexistent or not a directory: /Users/seckinpolat/Documents/MATLAB/trial.m

In path (line 109)
In addpath>doPathAddition (line 116)
In addpath (line 80)

Thanks!

@philipb314
Copy link
Member

Can you please try that last step again just the directory:

addpath('/Users/seckinpolat/Documents/MATLAB/')
And then try running ">> trial"

@seckinpolat
Copy link
Author

I run the lines that you sent me and I got the exact same errors

addpath('/Users/seckinpolat/Documents/MATLAB/')
Warning: Directory access failure: /Users/seckinpolat/Documents/MATLAB
In path (line 109)
In addpath>doPathAddition (line 116)
In addpath (line 80)

trial
Unrecognized function or variable 'trial'.

@philipb314
Copy link
Member

It seems the second time did return a slightly different error of "Directory access failure".
I am working with some internal teams to further investigate this issue and better understand what might be happening to trigger this particular warning.

In the meantime, the one thing I would like to see is if you can run a script from a different folder not under your "Documents" folder.

Additionally, what happens if you run ">> cd('/Users/seckinpolat/Documents/MATLAB/')"?
What about ">> cd('/Users/')"?

Thanks for the help!

@philipb314
Copy link
Member

Hello seckinpolat,

In addition to what I mentioned above, I have a few more questions that would really help us figure this out.

  1. Are you running VS Code/MATLAB on a personal machine or a work machine?

  2. This is more likely if this is a work machine, but do you know if your personal home folder or Documents folder is in any way special? Perhaps it is stored on the network and not locally?

  3. Can you try running

builtin('_canonicalizepath', '/Users/seckinpolat/Documents/MATLAB/trial.m')
and sending us the results. We expect it to error with message as before.

  1. At the MATLAB terminal within VS Code, can you run the following commands:

!ls '/Users/seckinpolat/Documents/MATLAB/'
!cat '/Users/seckinpolat/Documents/MATLAB/trial.m'

Feel free to redact the results. We are more interested in whether they error out or if they work.

  1. At a normal system terminal (not MATLAB) can you run these commands:
    ls '/Users/seckinpolat/Documents/MATLAB/'
    cat '/Users/seckinpolat/Documents/MATLAB/trial.m'

From what you have said, I expect those to work.

Thanks again for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants