mathworks / MATLAB-extension-for-vscode

This extension provides support for editing MATLAB® code in Visual Studio® Code and includes features such as syntax highlighting, code analysis, navigation support, and more.
https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab
MIT License
241 stars 16 forks source link

Matlab Does Not Run Codes on Visual Studio Code #147

Open seckinpolat opened 6 months ago

seckinpolat commented 6 months ago

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

Thank you for your help in advance.

philipb314 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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

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

seckinpolat commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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.

4) 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.

5) 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!