I know this is a duplicate but none of the answers published already are solving my problem . im using mac and trying to stop matlab runing with cmd + .
or cmd + c . pressing for long time does not help .
any suggestion?
Ctrl + C? Some heavy Matlab calls may be un-interuptable in this way, but mostly this should work.
If you don't care about the intermediate results or the content of your global workspace, you could always kill MATLAB's process.
Next time you'll run a script with huge loops, take the advice of including some function calls that will transfer briefly the control to the user interface: drawnow, getframe etc.
For Octave 4.4.1 GUI, on MacOS 10.14 Mojave, to exit code mid execution I use:
For code that is paused:
option + c
For code stuck in a loop:
control + c
You may need to hold this down for a few seconds
Related
I just started having this problem a few hours ago, and before that I never had this issue.
I am writing a code in Julia using VS Code also using Julia Repl and Revise. Since a few hours every time I make a change in the code I have to restart VS Code to be able to run my recently saved code. Otherwise, if I do not restart the code, terminal just tells that it is finished and the code ran already, which actually did not happen.
Does anyone have an idea how to solve this, or what the problem could be?
Thanks in advance!
I tried to save it different ways, and searched for similar problem online, but did not really find anything useful.
What if you restart the REPL inside the VSCode instead of restarting the whole program?
For this, you can use this key shortcut: Ctrl + J Ctrl + R. Also, you can find it using Ctrl + Shift + P and the search for Restart REPL.
For me, however, this didn't happen unless I wrote the code so it couldn't be mutated after the first run. For example, I can't redefine a composite type in Julia, and I do need to restart the Julia session to do it.
I have started running a script on MATLAB that takes days to finish. Usually, if I changed my mind and I don't want wait for it to finish and I get content with the intermediate results, I highlight the command window and press Ctrl-C to break the code.
Now, I have run MATLAB. But its desktop got kinda stuck in the background. When I try to restore the desktop from the toolbar, it does not restore. But I know from the task manager that the process is running and is consuming Memory and CPU performance. So, I am kinda stuck. I don't want to kill the process because I need the intermediate values in the workspace, and I can't open the desktop to break the code using ctrl-c.
Is there any solution? For example, is there any command that can be used in the command prompt to act as ctrl-c for MATLAB?
I am using MATLAB R2012b and Windows 8.
Quick try to fix the recent Problem:
Try ty set a higher priority to matlab.exe in the Task Manager. (Right click -> Priority -> Higher than normal). Then see if you can get the window to front.
Some approaches to avoid this problem in future:
Try to optimize your code. For starters look at: http://de.mathworks.com/help/matlab/matlab_prog/vectorization.html
Use Matlab compiler for faster execution: http://de.mathworks.com/products/compiler/
Include some drawnow commands at stratetic positions in the code. This allows matlab to process the Event Queue and capture ctr-C commands.
Save intermediate results to output files. For example you could write an output file all 30 min with your intermediate results. Easyiest way would be just save(filename). Then a .matfile with all your workspace variables is generated. You can than kill the process in the task manager, without loosing too much results.
In Matlab or GNU Octave, this command input("") allows to break the input process by pressing CTRL+C or CTRL+Z. Is there a way to block this, so that only a valid input is accepted?
Note: Pressing CTRL+Z on an input command even exits the Octave shell in a Linux terminal, so I understand that the control must be established at a different layer.
So you want input to ignore when Ctrl + C is pushed? I don't think that's possible simply because this could potentially be dangerous. Ignoring listening to Ctrl + C could open the possibility of your code running endlessly and you not being able to break out of the code unless you manually kill MATLAB. I'm not saying that what you desire with input will be dangerous, but if MATLAB allowed you to ignore this keystroke in any capacity, then you'd have that dangerous situation that I talked about if used improperly.
FWIW, check out this link on MATLAB Central: http://www.mathworks.com/matlabcentral/answers/25213-disabling-ctrl-c-in-a-gui . Here, someone is trying to ignore Ctrl + C so that their GUI doesn't needlessly crash, but MathWorks confirms that it is not possible to do so.
This question already has answers here:
Stop and continue execution from debugger possible?
(6 answers)
Closed 8 years ago.
Strg+C stops and kills a Matlab script (at least sometimes). But is there a way to stop a Matlab, take a look at some variables and continue the calculation?
I am not talking about just setting a breakpoint. I want my script, let’s say run for couple hours come back to it hit some buttons that stops the calculations take a look at some variable and then continue the calculation.
I tried to find out if there is some shortcut key for this – I am quite sure there isn’t.
Now I was thinking about including an if-case that looks if a certain button was pressed by the user. If so there would be a useless k=0 line and a breakpoint on it. And if no one is pressing this button the loop would continue. But this is where my limited Matlab knowledge leaves me. I don’t know if there is a way to ask for a user-button press but don’t wait for a button press like in the function input. Also I just have a running script, I don’t have any GUI.
To drop to the command prompt you need the command keyboard and then type return when you have finished (you don't need a breakpoint). The tricky bit is how to trigger it. There a few options. The easiest is to open a figure window. The following code halts the process when any key is pressed.
keyDownListener=#(src,event) keyboard;
fig = figure;
drawnow
set(fig,'KeyPressFcn',keyDownListener)
for p=1:10000
%do some thing
end
You can modify this to test for a specific key since the keypress is contained within the event struct.
To use no figure gui at all its more of a problem. I'm not aware of a non blocking keyboard input method. A mex file the runs kbhit() in C might do it, but kbhit() is not standard C so it would only work on Windows. An easier option maybe to test for the presence of a file.
for p=1:100000
if exist(fullfile(pwd,'halt.tmp'),'file')
keyboard
end
%do something here
end
This drops to the debug console when halt.tmp is created in the current directory.
Other potential methods could involve using multiple threads to read 'input' (either the Parallel computer toolbox or undocumented Java code), or using http://psychtoolbox.org/ as mentioned by #bdecaf
I'm fairly new to Gtk. I'm working on a GUI application. Everything works great until I press Ctrl + C, Ctrl + V to copy/paste (in an outside application like excel). I am using Windows 8 64bit with a Mingw 32bit compiler. Any help on this issue would be appreciated.
I managed to hit the same assertion error by inducing infinite recursion (my trick was to call paste_clipboard() inside a paste_clipboard signal handler - fun fun!). Possibly you had something that responded to a clipboard change by changing the clipboard?