VS Code配置 | Matlab

前言:本文介绍了在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
    • 下载后将文件夹复制到工作空间,此后的新工作空间对此文件夹进行复制即可。
  • 更改matlab.exemlint.exe路径在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值