This code snippet causes Matlab to crash
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Rik
2017년 12월 22일
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.
채택된 답변
Rik
2017년 12월 22일
(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
Rik
2017년 12월 22일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!