LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

MATLABを立ち上げずにプログラムを実行する方法を探してみた

Last updated at Posted at 2023-12-05

はじめに

Markdown形式で記事を書くことに慣れるという名目のもと、ここ最近 僕がMATLABについて試したことをまとめておきます。

(初心者なので慣れていない点は悪しからず......)

MATLABを使っていてふと思ったのですが、前に作ったプログラムを少しだけ動かしたいとき、いちいちMATLABを立ち上げるのって面倒くさくないですか?
ということで、MATLABを立ち上げなくても手軽にプログラムを実行できる方法を探してみました。

動作環境

  • Visual Studio Code (1.84.2)
  • MATLAB R2023a (Update 5)

Visual Studio Code で MATLAB

結論から言うと、Visual Studio Codeに拡張機能をインストールすることで実現できました。

拡張機能のインストール

Visual Studio Code に以下の拡張機能をインストールしました。

エディタ内の左側ペインから拡張機能を選択し、検索することでインストールできます。
インストール後の設定は特に不要です。

VSCode 左側ペインの拡張機能

使い方

はじめに、Visual Studio Code のステータスバーに「MALTAB:Connected」と表示されていることを確認してください。

Connected

次に、実行したいプログラムを開いた状態で、「Ctrl+Shift+P」でコマンドパレットを開き、「Run Matlab File」を実行してください。
すると、MATLAB Command Windowが起動して出力が表示されます。

例えば、

sample.m
clear; clc;

x = -pi:0.01:pi;
plot(x,sin(x)), grid on

を作成して「Run Matlab FIle」実行すると自動でターミナルが起動し、

ターミナル

MATLAB Command Window と出力が表示されます。

MATLAB Command Window

終わりに

Visual Studio Code の拡張機能を使って、MATALBを立ち上げずにプログラムを実行することができました!
でも、普通にMATLABを開いた方が早いかもしれません。(笑)

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