Main Content

close

1 つ以上の Figure を閉じる

説明

close は、現在の Figure を閉じます。close を呼び出すことは close(gcf) を呼び出すことと同等です。

close(fig)fig で指定された Figure を閉じます。

close all はハンドルが表示されているすべての Figure を閉じます。HandleVisibility プロパティが 'callback' または 'off' に設定されている場合、Figure ハンドルは非表示です。

close all hidden は、ハンドルが非表示の Figure を含むすべての Figure を閉じます。

close all force は、ユーザーにより Figure ウィンドウが閉じられることを防ぐために CloseRequestFcn コールバックが指定されている Figure を含めた、すべての Figure を閉じます。

status = close(___) は前述の任意の構文に対して閉じる操作の status を返します。関数は Figure が閉じた場合 1 を返し、そうでない場合は 0 を返します。出力 status を指定する場合は、文字ベクトルである入力引数を status = close('all','hidden') のようにかっこで囲まなければなりません。

すべて折りたたむ

それぞれがライン プロットをもつ 2 つの Figure を作成します。

f1 = figure;
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

f2 = figure;
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

最初の Figure を閉じて、f1 の値を表示します。

close(f1)
f1
f1 = 
  handle to deleted Figure

現在の Figure を閉じます。

close

3 つの Figure を作成してから、ライン プロットを作成します。既定では、関数 plot のターゲットは現在の Figure (f3) です。

f1 = figure;
f2 = figure;
f3 = figure;
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

Figure f1f2 を同時に閉じます。

close([f1 f2])

指定した番号をもつ 2 つの Figure を作成します。各 Figure にライン プロットを含めます。

figure(1)
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

figure(2)
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

関数 close にその番号を渡すことにより、2 番目の Figure を閉じます。

close(2)

Figure を作成し、その名前を指定してから、ライン プロットを作成します。

figure('Name','Measured Data');
plot(1:10)

Figure Measured Data contains an axes object. The axes object contains an object of type line.

その名前を使用して Figure を閉じます。

close('Measured Data')

それぞれがライン プロットをもつ 2 つの Figure を作成します。

f1 = figure;
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

f2 = figure;
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

Figure f1 を閉じます。そのステータスを表示することにより、Figure が閉じていることを検証します。

status = close(f1)
status = 1

ハンドルが表示される 3 つの Figure を作成して、各 Figure にライン プロットを含めます。

f1 = figure;
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

f2 = figure;
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

f3 = figure;
plot(1./(1:10))

Figure contains an axes object. The axes object contains an object of type line.

すべての Figure を同時に閉じます。

close all

それぞれがライン プロットをもつ 3 つの Figure を作成します。最後の Figure の HandleVisibility プロパティを 'off' に設定します。

f1 = figure;
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

f2 = figure;
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

f3 = figure('HandleVisibility','off');
plot(1./(1:10))

Figure contains an axes object. The axes object contains an object of type line.

すべての Figure を閉じます。非表示ハンドルがあるため、close all を呼び出しても f3 を閉じることはできないことに注意してください。

close all hidden

CloseRequestFcn プロパティにより、ユーザーが Figure ウィンドウを閉じようとすると必ず実行されるクローズ要求のコールバックを指定できます。たとえば、ダイアログ ボックスを表示して、閉じる操作の確定またはキャンセルをユーザーに求めたり、UI を含む Figure を閉じる操作をユーザーからはできないようにしたりできます。

CloseRequestFcn プロパティを空の文字ベクトルに設定し、ウィンドウを閉じることができない Figure を作成します。次に、Figure にライン プロットを追加します。

f1 = figure('CloseRequestFcn','');
plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

ライン プロットをもつ 2 番目の Figure を作成します。

f2 = figure;
plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

close all 構文を使用して Figure を閉じようとすると、MATLAB® では f2 のみが閉じられます。f1f2 を両方閉じる場合は、close all force 構文を使用します。

close all force

入力引数

すべて折りたたむ

閉じる Figure。1 つ以上の Figure オブジェクト、Figure 番号、または Figure 名として指定します。

  • fig が Figure 番号の場合、MATLAB®Number プロパティが fig と同等である既存の Figure を検索します。既定で Number プロパティ値は、Figure のタイトルに表示されます。

  • fig が Figure 名の場合、MATLAB は Name プロパティが fig と同等の既存の Figure を検索します。

例: close(f) は、ハンドル f をもつ Figure を閉じます。

例: close([f1 f2]) はハンドル f1f2 をもつ Figure を閉じます。

例: close(1) は番号が 1 の Figure を閉じます。

例: close([1 2]) は番号が 12 の Figure を閉じます。

例: close('My Figure') は名前が 'My Figure' の Figure を閉じます。

例: close('My First Figure','My Second Figure') は名前が 'My First Figure''My Second Figure' の Figure を閉じます。

ヒント

  • すべての Figure を無条件で削除するには、以下のステートメントを使用します。

    set(groot,'ShowHiddenHandles','on')
    c = get(groot,'Children');
    delete(c)

  • CloseRequestFcn コールバックを実装する場合、close への呼び出しを使用しないでください。コールバックの本文で close を呼び出すと、再帰が設定され、結果的に MATLAB の警告が表示されます。代わりに、関数 delete を使用してコールバックを実装します。deleteCloseRequestFcn コールバックを実行せずに Figure を削除します。

  • CloseRequestFcn プロパティを指定せずに Figure で close を呼び出すと、プロパティの既定値である closereq は Figure を無条件で削除し、そのウィンドウを閉じます。close を呼び出すときに削除しないようにするには、CloseRequestFcn コールバックを実装します。

アルゴリズム

関数 close は、次のステートメントを使用して指定された Figure fCloseRequestFcn プロパティを評価します。

eval(get(f,'CloseRequestFcn'))

CloseRequestFcn により、close が呼び出された後に Figure が閉じるのを遅らせたり破棄することができます。たとえば、ダイアログ ボックスを表示し、Figure を本当に閉じてもよいか、あるいは閉じる前に保存とクリーン アップを行うかを確認することも可能です。

CloseRequestFcn の既定値である closereq は、delete(get(groot,'CurrentFigure')) を使用して現在の Figure を閉じます。Figure ハンドルの配列を指定する場合、close は各 Figure に対する CloseRequestFcn で指定されたコールバックを実行します。

エラーによって CloseRequestFcn コールバックの実行が強制終了されると、Figure は閉じられません。

バージョン履歴

R2006a より前に導入

参考

関数

プロパティ