Main Content

msgbox

メッセージ ダイアログ ボックスを作成

説明

メモ

App Designer 内および関数 uifigure で作成されたアプリ内では、msgbox よりも uialert の方が、追加のカスタマイズ オプションを使用できるため推奨されます。

f = msgbox(message) は、適切なサイズの Figure に収まるように message を自動的に折り返すメッセージ ダイアログ ボックスを作成します。

複数のアプリ ウィンドウ、MATLAB® デスクトップ、または Simulink® でメッセージ ダイアログ ボックスを表示し、ダイアログ ボックスに応答する前にそれらを操作できるようにする場合は、この関数を使用します。

f = msgbox(message,title) は、メッセージ ボックスのタイトルを指定します。

f = msgbox(message,title,icon) は、メッセージ ダイアログ ボックスに表示する事前定義されたアイコンを指定します。

f = msgbox(message,title,"custom",icondata,iconcmap) は、メッセージ ダイアログ ボックスに含めるカスタム アイコンを指定します。icondata はアイコンを定義するイメージ データです。iconcmap はイメージに使用されるカラーマップです。icondata がトゥルーカラー イメージ配列の場合、iconcmap を指定する必要はありません。

f = msgbox(___,createmode) は、ダイアログ ボックスのウィンドウ モードを指定します。また、ウィンドウ モードと message のインタープリターを指定する構造体配列を指定することもできます。

すべて折りたたむ

メッセージ ダイアログ ボックスに表示するテキストを指定します。

f = msgbox("Operation Completed");

Message dialog box with the text "Operation Completed" and an OK button at the bottom

string 配列を使用して、メッセージ ダイアログ ボックスのテキストを指定します。

f = msgbox(["Operation";"Completed"]);

Message dialog box with the text "Operation Completed" split over two lines and an OK button at the bottom

メッセージ ダイアログ ボックスのテキストを指定し、ダイアログ ボックスに Success というタイトルを付けます。

f = msgbox("The operation has been successfully completed","Success");

Message dialog box with the text "The operation has been successfully completed" and an OK button at the bottom. The dialog box title is "Success".

Error というタイトルのメッセージ ダイアログ ボックスにエラー メッセージとともに組み込みのエラー アイコンを含めます。

f = msgbox("Invalid Value","Error","error");

Message dialog box with the title "Error" and the text "Invalid Value". The dialog box contains a red error icon to the left of the text.

RGB イメージをワークスペースに読み取ります。次に、その配列をダイアログ ボックスのカスタム アイコンとして指定します。

myicon = imread("landOcean.jpg");
h = msgbox("Operation Completed","Success","custom",myicon);

Message dialog box with the title "Success" and the text "Operation Completed". The dialog box contains an icon of a world map to the left of the text.

イメージ データとカラーマップをワークスペースに読み取ります。

[icondata,iconcmap] = imread("trees.tif"); 

カスタム アイコンを含むメッセージ ダイアログ ボックスを作成します。

h = msgbox("Operation Completed", ...
         "Success","custom",icondata,iconcmap);

Message dialog box with the title "Success" and the text "Operation Completed". The dialog box contains an icon of a tree to the left of the text.

別のカラーマップを指定してイメージの色を調整します。たとえば、MATLAB 組み込みのカラーマップ summer を指定します。

h = msgbox("Operation Completed","Success","custom", ...
          icondata,summer);

Message dialog box with the title "Success" and the text "Operation Completed". The dialog contains an icon of a tree using the green-and-yellow summer colormap to the left of the text.

ユーザーがメッセージ ダイアログ ボックスに応答するまでメッセージ ダイアログ ボックスで MATLAB の実行がブロックされるように、msgbox の呼び出しを uiwait でラップしてモーダル メッセージ ダイアログ ボックスを作成します。

uiwait(msgbox("Operation Completed","Success","modal"));

Message dialog box with the title "Success", the text "Operation Completed", and an OK button at the bottom

ユーザーが別のウィンドウを操作する前に [OK] をクリックしなければならないこと、および MATLAB がメッセージ テキストを TeX 形式として解釈することを指定する構造体を作成します。

CreateStruct.Interpreter = 'tex';
CreateStruct.WindowStyle = 'modal';

メッセージ ダイアログ ボックスを作成します。

h = msgbox("Z = X^2 + Y^2","Value",CreateStruct);

Message dialog box with the title "Value" and a formatted equation with superscripts

入力引数

すべて折りたたむ

ダイアログ ボックスのテキスト。文字ベクトル、文字ベクトルの cell 配列、または string 配列として指定します。

例: "Operation Completed"

例: ["Operation";"Completed"]

タイトル。文字ベクトルまたは string スカラーとして指定します。

例: "Success"

アイコン。"help""warn""error"、または "none" として指定します。

次の表は、値とそれに対応するアイコンのリストです。

アイコン
"help"

Square blue icon with a lowercase "i" character

"warn"

Triangular yellow icon with an exclamation point

"error"

Octagonal red icon with an exclamation point

"none"アイコンは表示されません。

イメージ配列。m 行 n 列の配列または m×n×3 のトゥルーカラー イメージ配列として指定します。imread を使用してファイルからイメージ配列を取得することもできます。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

カラーマップ。RGB 3 成分からなる 3 列の行列として指定します。RGB 3 成分は、各要素が色の赤、緑、青の成分の強度を指定する 3 要素の行ベクトルです。強度値は [0, 1] の範囲でなければなりません。

データ型: single | double

ウィンドウ モード。"non-modal""modal""replace"、または構造体配列として指定します。

  • createmode"non-modal" の場合、MATLAB は指定されたパラメーターを使用して新規の非モーダルなメッセージ ボックスを作成します。同じ title をもつ既存のメッセージ ボックスはそのまま残ります。

  • createmode"modal" の場合、MATLAB は指定された title をもつ既存のメッセージ ボックスのうち最後に作成またはクリックされたものを、指定されたモーダル ダイアログ ボックスに置き換えます。同じタイトルをもつその他すべてのメッセージ ボックスは、MATLAB によって削除されます。置き換えられるメッセージ ボックスは、モーダルまたは非モーダルのいずれかです。

  • createmode"replace" の場合、MATLAB は指定された title をもつメッセージ ボックスのうち最後に作成またはクリックされたものを、指定に応じて非モーダル メッセージ ボックスに置き換えます。同じタイトルをもつその他すべてのメッセージ ボックスは、MATLAB によって削除されます。置き換えられるメッセージ ボックスは、モーダルまたは非モーダルのいずれかです。

  • createmode が構造体配列の場合は、WindowStyle フィールドと Interpreter フィールドがなければなりません。WindowStyle フィールドの値は "non-modal""modal"、または "replace" でなければなりません。Interpreter フィールドの値は "tex" または "none" でなければなりません。Interpreter の値が "tex" の場合、MATLAB は message の値を TeX として解釈します。Interpreter の既定値は "none" です。

TeX マークアップ

MATLAB では、既定で TeX マークアップのサブセットをサポートしています。TeX マークアップを使用して、上付き文字や下付き文字の追加、フォントのタイプや色の変更、テキストへの特殊文字の挿入を行うことができます。

修飾子の効果はテキストの末尾まで適用されます。上付き文字と下付き文字は例外であり、次の 1 文字または中かっこで囲まれた文字にのみ適用されます。インタープリターを 'tex' に設定した場合にサポートされる修飾子は次のとおりです。

修飾子説明
^{ }上付き文字'text^{superscript}'
_{ }下付き文字'text_{subscript}'
\bf太字フォント'\bf text'
\itイタリック フォント'\it text'
\sl斜体フォント (通常はイタリック フォントと同じ)'\sl text'
\rm標準フォント'\rm text'
\fontname{specifier}フォント名 — specifier をフォント ファミリの名前に置き換えます。これは他の修飾子と組み合わせて使用できます。'\fontname{Courier} text'
\fontsize{specifier}フォント サイズ — specifier をポイント単位の数値スカラーに置き換えます。'\fontsize{15} text'
\color{specifier}フォントの色 — specifier を、redgreenyellowmagentablueblackwhitegraydarkGreenorangelightBlue の色のいずれかに置き換えます。'\color{magenta} text'
\color[rgb]{specifier}フォントのカスタムの色 — specifier を RGB 3 成分に置き換えます。'\color[rgb]{0,0.5,0.5} text'

次の表に、'tex' インタープリターでサポートされる特殊文字を示します。

文字列記号文字列記号文字列記号

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

ϕ

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ϵ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

出力引数

すべて折りたたむ

ダイアログ ボックスの Figure オブジェクト。f を使用してダイアログ ボックスのプロパティのクエリと変更を行います。

詳細

すべて折りたたむ

モーダル ダイアログ ボックス

モーダル ダイアログ ボックスでは、モーダル ダイアログ ボックスに応答する前に他の MATLAB ウィンドウを操作することができません。

非モーダル ダイアログ ボックス

非モーダル ダイアログ ボックスでは、非モーダル ダイアログ ボックスに応答する前に他の MATLAB ウィンドウを操作できます。非モーダル ダイアログ ボックスはノーマル ダイアログ ボックスとも呼ばれます。

ヒント

  • モーダル ダイアログ (errordlgmsgbox または warndlg で作成) は、これらの関数で作成された同名の既存のダイアログを置き換えます。

  • プログラムの実行は、モーダル ダイアログ ボックスがアクティブであっても続行されます。モーダル ダイアログ ボックスにユーザーが応答するまで MATLAB プログラムの実行をブロックする場合は、関数 uiwait を使用します。

  • 単一ウィンドウの App Designer または uifigure ベースのアプリ向けにモーダル警告ダイアログ ボックスを作成するには、代わりに関数 uialert を使用します。

バージョン履歴

R2006a より前に導入