Alfonso Nieto-Castanon - MATLAB Cody - MATLAB Central

Alfonso Nieto-Castanon

129646
Rank
1
Badge
10
Score
1 – 5 of 5

Alfonso Nieto-Castanon submitted a Comment to Problem 1917. click away

@Rafael. Assuming you are referring to the "x=msgbox('Ok'); while ishandle(x), disp('hello world'); end" code, then yes, the figure closes and the loop does NOT break, as one could expected (as the CloseRequestFcn callback, containing the "delete(gcbf)" code, is NOT executed so the loop continues forever). The behavior, of course, is different if you add back the "pause(1)" line within the loop. In that case the figure closes AND the loop ends (since, once the pause command is executed after the figure is closed, that will cause the CloseRequestFcn callback to be executed, which in turn will run the "delete(gcbf)" command, which in turn will make "x" a no-longer-valid graphic handle, which will cause the "ishandle(x)" condition to fail when it gets there). Are you observing the same behavior? (I am on R2020b, perhaps some of this is different in pre-R2014b versions?)

on 21 Oct 2020

Alfonso Nieto-Castanon submitted a Comment to Problem 1917. click away

and btw, your 'x=msgbox('Ok'); while ishandle(x), disp('hello word!'); pause(2); end' code works (meaning that the loop ends when you click on the 'Ok' button) only because of the "pause" command within the loop. Remove that and it will not work at all. Why? you may ask. Well, pause, exactly like drawnow, will force any pending callbacks to be processed (again, this is detailed in "help drawnow"), so, without it, "ishandle" never notices whether you have clicked on the message box button (because the associated button callback function is not yet been executed), or whether you have even closed the entire message box (because the associated figure CloseRequestFcn callback has not yet been executed). Hope this helps clarify

on 19 Oct 2020

Alfonso Nieto-Castanon submitted a Comment to Problem 1917. click away

@Rafael. Sorry I am not being very clear, let me start again. The objective of this problem is that players write some code that effectively "clicks on the 'Ok' button" of a message box. In other words, your clickOK() code should have exactly the same effect as if you magically sat on the same computer running the testsuite, saw that message box being created by the testsuite, and immediately used your mouse to click on the 'Ok' button all before your clickOK() function finishes. When you (magically) click on the 'Ok' button, the button callback function will NOT be run immediately. It will actually not be run at all until after the clickOK() function finishes executing entirely, and even then it will not be run just yet. The testsuite will continue running taking priority over your mouse click callback (just like in the infinite loop example) right until the point when the testsuite executes a "drawnow" command. At that point, if you or your function have in fact clicked on the Ok button, the drawnow command will realize that it has a callback pending to be executed and it will run it (see drawnow documentation), which, in turn, will cause the message box to be closed. After that the testsuite will continue running as normal, it will then check that the message box has been closed (note that it was not closed before the drawnow command), and you will "pass" this problem. That's all. Hope this helps

on 19 Oct 2020

Alfonso Nieto-Castanon submitted a Comment to Problem 1917. click away

@Rafael, your PC might generate an interrupt when the mouse is clicked, but that will only tell MATLAB that the mouse was clicked, it is then up to MATLAB runtime to decide what to do with it. And Matlab decides to ignore it for now if some code (in this case the testsuite) is already running until a drawnow command is run, or until the code returns to the Matlab prompt, or until the code issues a waitfor command, etc. (see "help drawnow" for more details). That is NOT the same as if the running code itself (in this case the testsuite) calls the callback function, in which case Matlab runtime will decide to execute that function, not the "ignore it for now" behavior you can expect from a mouse click. If in doubt, try the following: "msgbox('Ok'); while 1, end" and then click on the 'Ok' button. Hope this helps clarify

on 18 Oct 2020

Alfonso Nieto-Castanon received Commenter badge for Problem 1917. click away

on 18 Oct 2020

1 – 5 of 5
Go to top of page