前言:本文介绍了在VS code中配置Matlab环境,利用插件可以实现代码编译的高亮标注,自动补全等,并可以调用Matlab运行代码。
Step 1:安装Matlab
安装教程:安装 | MATLAB2018a (64位) 安装教程及安装包下载链接
Step 2:安装VS code插件
-
VS Code插件安装方法
- 点击左侧插件选项卡(Extensions),或者按Ctrl+Shift+X
- 输入你想要的插件
- 点击插件,安装(Install)
-
配置所需的插件
-
Matlab
-
Code Runner
-
matlab-formatter
-
Step 3:插件配置
方式一:插件设置中进行配置
进入插件设置界面
-
Matlab
-
Code Runner
-
进入setting.json设置
-
添加代码
# 添加代码内容 "matlab": "cd $dir && matlab -nosplash -nodesktop -r $fileNameWithoutExt", # 命令意义 cd $dir # 进入当前文件夹 matlab -nosplash -nodesktop -r $fileNameWithoutExt # -nosplash表示启动时不显示图标 # -nodesktop表示只启动命令行形式的matlab # -r表示只读该文件 # $fileNameWithoutExt表示该文件的名称,并且不带后缀名
-
-
其他配置
在setting.json中设置
-
"files.associations"让VSC识别.m文件为matlab文件
"files.associations": { "*.m": "matlab", },
-
让code-runner的结果在Terminal中显示
"code-runner.runInTerminal": true,
-
方式二:settings.json文件进行配置
- 在工作区内创建文件夹 .vscode,并在文件夹下创建文件setting.json
-
在文件中写入如下代码
{ "matlab.matlabpath": "D:\\MATLAB\\bin\\matlab.exe", "matlab.mlintpath": "D:\\MATLAB\\bin\\win64\\mlint.exe", "matlab.linterEncoding": "gb2312", "code-runner.executorMap": { "matlab": "cd $dir && matlab -nosplash -nodesktop -r $fileNameWithoutExt", "javascript": "node", "java": "cd $dir && javac $fileName && java $fileNameWithoutExt", "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "php": "php", "python": "python -u", "perl": "perl", "perl6": "perl6", "ruby": "ruby", "go": "go run", "lua": "lua", "groovy": "groovy", "powershell": "powershell -ExecutionPolicy ByPass -File", "bat": "cmd /c", "shellscript": "bash", "fsharp": "fsi", "csharp": "scriptcs", "vbscript": "cscript //Nologo", "typescript": "ts-node", "coffeescript": "coffee", "scala": "scala", "swift": "swift", "julia": "julia", "crystal": "crystal", "ocaml": "ocaml", "r": "Rscript", "applescript": "osascript", "clojure": "lein exec", "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt", "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt", "racket": "racket", "scheme": "csi -script", "ahk": "autohotkey", "autoit": "autoit3", "dart": "dart", "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt", "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt", "haskell": "runhaskell", "nim": "nim compile --verbosity:0 --hints:off --run", "lisp": "sbcl --script", "kit": "kitc --run", "v": "v run", "sass": "sass --style expanded", "scss": "scss --style expanded", "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css" }, "files.associations": { "*.m": "matlab", }, "code-runner.runInTerminal": true, "[matlab]" : { "files.encoding": "gb2312", }, "files.autoGuessEncoding": true, }
settings.json文件下载链接
- 网盘链接:.vscode
提取码:xmxc - 下载后将文件夹复制到工作空间,此后的新工作空间对此文件夹进行复制即可。
- 网盘链接:.vscode
-
更改matlab.exe和mlint.exe路径