32
24

More than 3 years have passed since last update.

VScodeでMatlabファイルを実行する

Last updated at Posted at 2019-11-29

したいこと

  • VScode上でMatlabファイル(.m)を編集
  • そのままVScodeで実行
  • Figure表示

導入

  1. 拡張機能「Matlab」と「Matlab Code Run」をVSCにインストール
    Matlab
    Matlab Code Run

  2. VSC上のユーザ設定(Ctrl+,)から設定の検索で「matlab」と打ち込むとMatlab拡張機能のconfigがヒットする(下図)
    image.png

  3. Matlab:MatlabpathMatlab:Mlintpathにmatlabとmlintのexeファイルを指定
    exeファイルの場所はデフォルトだとそれぞれ,
    C:\Program Files\MATLAB\R2019a\bin\matlab.exe
    C:\Program Files\MATLAB\R2019a\bin\win64\mlint.exe
    になっているはず.

これで拡張機能の設定は完了.

実行

適当にMatlabを実行するフォルダとファイル(.m)を作成し,VSCでワークスペースを開く.

test.m

close all;
clear;
clc;

foo ='Hello World';
x = rand(3,3)

プログラムが書けたら「Ctrl+Shift+P」でコマンドパレットを開く.
コマンドパレットからRun Matlab Fileを実行すると,MATLAB Command Windowが起動し出力が表示される.

image.png

Figureも表示される

image.png

不具合

  • Matlab Code Runで,初回はRun Matlab Fileで正常に実行されるが,二回目の実行の際では実行コマンドがrun('./[file].m')となっており実行できない.
    • 自分でコマンドを叩かないといけない(致命的)
    • issue投げて直してもらう....(?)
  • 実行する度にMATLAB Command Windowが起動するので多窓になる.
    • コマンド引数で何とかなりそう(?)

まとめ

  • VSCでMatlabの実行はできる.
  • Matlab Code Runが不完全なので快適に開発はできない.
    • 結局VSCでは実行できていない.
  • 修正を待つか拡張機能を自作する必要がある.

[追記]
現在(2019/11/29)拡張機能はLinux, Macで正常に動作するようでした.Windows対応まで座して待ちましょう...

32
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
24