How to kill an execution in app designer ?

59 ビュー (過去 30 日間)
farzad
farzad 2020 年 5 月 2 日
コメント済み: Matlab_Beginner 2022 年 8 月 30 日
Hi All
How can I put a push button that has the same function of Ctrl+C in MATLAB workspace ? that can kill an execution immediately ?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 2 日
Use this undocumented MATLAB command to send a Ctrl+C to the MATLAB command window
com.mathworks.mde.cmdwin.CmdWinMLIF.getInstance().processKeyFromC(2,67,'C')
  13 件のコメント
farzad
farzad 2020 年 5 月 3 日
will the problem resolve with that ?
Ameer Hamza
Ameer Hamza 2020 年 5 月 3 日
No, it just equivalent to the code in my answer.
The only option which I can think of which might work in this case is to use the OutputFcn property of fsolve(). That outputFcn gives the option to terminate the fsolve() based on a condition. You just need to figure out a way to communicate button press to the outputFcn. For example, using a global variable (a simple approach but can cause issues in the long term) or pass a handle class to OutputFcn and change one of its properties based on the button press event. This is a general outline of the method. You can try it to see if it works.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 5 月 2 日
That's not a good idea. It would be better to abort your code gracefully. Like have a check box on your GUI that says "Finish Now" and if the user checks it, it gets out of your function gracefully and leaves your program running. Like if you're in a loop
for k = 1 : 1000000
% Some intensive code.....
% Now see if user wants to bail out:
if app.chkFinishNow.Value
return; % or break. to get out of the function (if return is used), or the for loop (if break is used).
end
end
Doing it like you asked is very bad programming practice in my opinion, and probably most everyone else's also.
  5 件のコメント
Image Analyst
Image Analyst 2022 年 8 月 29 日
編集済み: Image Analyst 2022 年 8 月 29 日
@Matlab_Beginner Please start your own, new question.
For any while loop you must have a failsafe that kicks you out once the loop counter reaches some unreasonably high number, like a million or something
loopCounter = 0;
maxIterations = 1e6;
while loopCounter < maxIterations || someOtherCondition
someOtherCondition = whatever;
loopCounter = loopCounter + 1;
end
Matlab_Beginner
Matlab_Beginner 2022 年 8 月 30 日
Hey, thanks for ur quick answer. that s not exactly what im looking for. i want the user to stop the run whenever he want to via the stop button.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by