This code snippet causes Matlab to crash

1 visualización (últimos 30 días)
YS
YS el 22 de Dic. de 2017
Comentada: YS el 22 de Dic. de 2017
The below code snippet causes Matlab to crash repeatedly, and can anyone tell how to fix this issue? Thanks.
while 1
figure; plot(rand(100))
pause(3)
close all
end
My environment is Matlab R2017a on RHEL 6.9.
  2 comentarios
Rik
Rik el 22 de Dic. de 2017
Why not use explicit handles and avoid messy opening and closing? It shouldn't crash, so for that you should contact support, but the code itself shouldn't be necessary.
Stephen23
Stephen23 el 22 de Dic. de 2017
YS's "Answer" moved here:
@ Rik: OK, then treat this code snippet as my bug report... Any idea how to solve or bypass this tricky bug of Matlab? Really has been bothering me for a long while.

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 22 de Dic. de 2017
(Please use the comment field for responses, instead of the answer field)
On R2017b on 64 bit W10 I can't reproduce this (not with run section, nor by executing as script). As I said, use explicit handles and avoid closing and clearing everything, as that can lead to unexpected results.
f=figure;
ax=axes('Parent',f);
while 1
cla(ax);
plot(ax,rand(100));
pause(3)
end
  5 comentarios
Rik
Rik el 22 de Dic. de 2017
I don't understand why Matlab would crash with this code, but 'bugs' can have a broader meaning as 'unexpected behavior'.
If you open a figure somewhere in your code, and your user switches to another figure during execution, your code could assume the current figure is the figure to write all the plots to. This will then lead to that second figure being overwritten and the first one have outdated contents.
The close all you were using is an implicit close, as it will close unspecified figures, close(f) (or cla(ax) for that matter) is explicit in what object should be targeted. The latter will never lead to overwriting of secondary figures that the user selected half-way through execution of some code.
In short, bugs that lead to Matlab crashing are always something to look out for and might be un-preventable, while bugs that lead to unexpected behavior are avoidable by using handles to graphics objects.
YS
YS el 22 de Dic. de 2017
Nice and insightful explanations. Thanks a lot, Rik!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by