Borrar filtros
Borrar filtros

ライブスクリプトの出力をクリアする方法

11 visualizaciones (últimos 30 días)
flower
flower el 16 de Sept. de 2023
Comentada: flower el 20 de Sept. de 2023
figureが表示されるライブスクリプトを作成しています。
for文で複数のデータを回す際に、すべてのfigureが右画面に蓄積されていき、重くなってしまいます。
出力しないようにfor分内に、clfやcloseを入れてもクリアできません。
何か解決方法はありますでしょうか?
  2 comentarios
Dyuman Joshi
Dyuman Joshi el 16 de Sept. de 2023
Google translation -
Title > How to clear live script output
Description > I am creating a live script where a figure is displayed.
When passing multiple data using a for statement, all the figures accumulate on the right screen and become heavy.
Even if you put clf or close in the for section to prevent output, it cannot be cleared.
Is there any solution?
Dyuman Joshi
Dyuman Joshi el 16 de Sept. de 2023
Could you please share the code you are working with?

Iniciar sesión para comentar.

Respuesta aceptada

Tak
Tak el 16 de Sept. de 2023
Editada: Tak el 18 de Sept. de 2023
figure の Visibleプロパティをoffにすることで、ライブエディター上での表示をOFFにできます。
for n=1:5
figure('Visible','off')
surf(peaks)
end
ライブエディター上だけでなく、コマンドウィンドウから呼び出し実行した場合も figure ウィンドウが非表示になりますのでご注意ください。
  4 comentarios
Tak
Tak el 19 de Sept. de 2023
やりたいこととしては以下のような感じでしょうか。
  • ループ処理の中で複数の figure ウィンドウがある
  • 2回目以降はユーザー判断で解析継続/中止を判断したい
  • 複数の figure ウィンドウを1回目はライブエディター上で表示したい
  • 複数の figure ウィンドウを2回目以降は非表示にしたい
ループ処理の中断方法
やり方はいくつかありそうですが、ライブエディターでの実行環境となると keyboard コマンドを挟むことで一時中断でしょうか。継続する場合は ライブエディター タブの [続行] をクリックすることで処理が再開されます。
2回目以降のfigureウィンドウを非表示にする
上記の Hiro Yoshino 様のコメント でもある通り、ループ処理を抜けた後で close all が簡潔でよさそうでしたね。
というわけで…一括でプロパティ変更する方法については参考として。 findobj で figure オブジェクトを取得して set でまとめて変更できます。
for n=1:5
figure
surf(peaks)
figure
surf(peaks(20))
figure
surf(peaks(10))
if n==1
% ループ処理の中断
keyboard
end
end
% figure オブジェクトの Visible プロパティの一括変更 (close all でも可)
fig = findobj('Type', 'figure');
set(fig, 'Visible', 'off')
flower
flower el 20 de Sept. de 2023
@Hiro Yoshino 簡潔なご回答ありがとうございます。無事に解決しました。
@Tak 説明不足な点、補って頂きありがとうございます。close allで解決できましたが、findobjも実用性が高そうですね。今後利用したいと思います。ご紹介ありがとうございました。

Iniciar sesión para comentar.

Más respuestas (1)

Hiroshi Iwamura
Hiroshi Iwamura el 19 de Sept. de 2023
clear
close all
f = figure;
f.Visible = "off";
for n=1:5
plot(rand(10,2))
% drawnow % この2行は確認用
% pause(0.5)
end
ではいかがでしょう?
f.Visible = "on"; にしてしまうとポップアップするので、普通に表示させたい場合は4行目をコメントアウトします。
  2 comentarios
Hiroshi Iwamura
Hiroshi Iwamura el 19 de Sept. de 2023
あるいは描画が重いようであれば、データだけを書き換えるようにすると、少しは早くなります。
for n=1:5
if n == 1
p = plot(rand(10,2));
else
y = rand(10,2);
p(1).YData = y(:,1);
p(2).YData = y(:,2);
end
end
flower
flower el 20 de Sept. de 2023
回答ありがとうございます。for分の前でoffにするのは思いつかない方法でした。参考になりました。

Iniciar sesión para comentar.

Categorías

Más información sobre 対話型コントロールとコールバック en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!