15 Feb 2017

Close all messageboxes in Matlab

In matlab, user interaction could be easily achieved by using 'msgbox()' function. The format of calling the 'msgbox()' is: msgbox(msg,title,style,mode). It is also very useful to modify the 'style' parameters to customise the appearance of the message box. The build-in parameters are:
'none' - the default one if you didn't provide any parameter
'warn' - warning dialogue box
'help' - help dialogue box
'error' - error dialogue box

The last parameter 'mode' can be selected among 'modal', 'nonmodal', and 'replace'. Some examples are shown in the picture below.

But, how to close these dialogue boxes? You might though: are you kidding me? click on the button - that's as easy as breath. Yes, that's exactly what everyone will do for sure. Seriously, think about if you have hundreds, even thousands of these little evils created in a loop? - yeah, I know it's a bad idea to create these GUI elements in your code if you are doing something computational extensive. But I saw someone did this before. It might be a legacy code you are maintaining which never come across this warning before. Or you just started from a small dataset and need to debug in this way while you progresses gradually. It's even worse if you created these dialogue boxes using 'modal' mode - it means you can do nothing before closing them. That's the real nightmare!

Let's try to find a way of dealing with this!