LoginSignup
0
1

More than 5 years have passed since last update.

MATLAB > .mファイルを作って実行する > 関数の定義と利用

Last updated at Posted at 2017-11-13
動作環境
MATLAB Online R2017b

MATLABでの関数の作成と利用は以下のようだ。

  1. .mファイルを作る
    • 例: myScript_171114.m
  2. .mファイル内にファイル名と同じ関数を作る
    • 例: function myScript_171114()
  3. pathを通しておく
    • 同じフォルダにあればそのまま使える

実行

MATLAB Onlineにて試してみた。

myScript_171114.m
function myScript_171114()
"Hello world"

COMMAND WINDOWにて下記を実行する。

>> myScript_171114()

ans = 

    "Hello world"

戻り値のある関数

addScript_171114.m
function [res] = addScript_171114(lhs, rhs)    
    res = lhs + rhs;

COMMAND WINDOWにて下記を実行した。

>> res = addScript_171114(3,1)

res =

     4
0
1
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
0
1