MatLab, missing ->> in command line [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I use MATLAB R2012b, and for some reason occasionally when I put "bad stuff" in the command line, it executes, but then the --> arrow thing besides the $$f_x$$ symbol disappears and I can't do anything in the command line.
For instance if I write an if statement with nothing else, it erases that arrow thing.

That's because you're starting a loop. It's waiting for you to type the code to go within the loop, and it is terminated when you type end to end the loop. For example:
if(x==0)
y = y + 1;
end

When you see this it typically means that you did not finish a command yet. This most commonly occurs with statements like for or if.
Example:
if 1
Now you are inside the if statement, and not simply at the basic prompt. Therefore you will not see anything happen. This can be tested by continuing with:
1+1 %Normally outputs 2
Obviously nothing happens. You now have two choices. Either you realize that the if was there by mistake, and you cancel with CTRL+C. In this case you will not see any output. Of course you can also choose to finish the statement:
end

Related

emacs: control where emacs starts from ~/.emacs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
Running emacs 28 On win10:
I'd like to see code for ~/.emacs that makes emacs start in ~/ unless otherwise
directed from the command line.
For instance: If I start emacs by pressing the start menu, and then typing e m a c s
I want to be sure it starts in my home directory unless I type
e m a c s

Stopping/pausing execution in Matlab to check the value of the variables while running [duplicate]

This question already has answers here:
Stop and continue execution from debugger possible?
(6 answers)
Closed 6 years ago.
I am trying to write a program in Matlab which is quite large and I want to stop or pause the execution to see what my variables values are.
I want to stop or pause the execution to see what my variables are.
One alternative is to use keyboard:
keyboard pauses execution of a running program and gives control to
the keyboard. Place the keyboard function in a program at the location
where you want MATLAB® to pause. When the program pauses, the prompt
in the Command Window changes to K>>, indicating that MATLAB is in
debug mode. You then can view or change the values of variables to see
if the new values produce expected results. The keyboard function is
useful for debugging your functions.
To continue executing your function, type dbcont, or type dbquit to quit the debug mode.
If you want to view the variables after a given number of iterations you can insert if ii = stop_point; keyboard; where ii is the iterator of the loop.
Another option is:
Use dbstop. This is shown with an example from the documentation:
Set a breakpoint to stop when n >= 4, and run the code.
dbstop in myprogram at 4 if n>=4
myprogram
Yet another option is to manually insert breakpoints in the MATLAB editor. Click on the left side of the code to insert breakpoints (indicated by a red dot). Now you can view the variable by hovering the mouse over the variable names in the editor
Have a look at this very relevant link to get more information.
Note, the following paragraph is a direct copy of chappjc's answer here. Please upvote his/her answer if you like this approach!
With the release of R2016a, you can just hit the Pause button in the code editor and it will halt right away.
To pause the execution of a program while it is running, in the Editor
tab, click the Pause button. MATLAB pauses execution at the next
executable line*. When your code is running, the Start button will
turn into a pause:

MATLAB return current values on interrupt [duplicate]

This question already has answers here:
In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?
(3 answers)
Closed 7 years ago.
If I press Ctrl + C during the execution of a long loop, I lose all the work that has done so far. So is there a way in MATLAB that I can press Ctrl + C, but return the current variables?
so what I want as a pseudo-code :
for i=1:very_long
do_things();
if keypress(ctrlc_orsomeothercombo)
disp('Im bored!');
return;
end
end
Is this possible?
Thanks
If you turn stop on errors on, then interrupting it, even with ctrl+c, brings you to the place where it was executing and you have the whole workspace available:
dbstop if error

How to stop a Matlab script but don’t kill the process? [duplicate]

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

How do I minimize the use of same-hand keyboard fingering? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have been trying to rid myself of the bad habit of key-chording in Emacs using only one hand. That is, for C-x I want to use my right pinky to hit the right-Ctrl and a left-hand finger to hit x. My question is how do I type efficiently in all caps? For example, when I type an environment variable such as RAILS_ENV=test it's very tedious to switch between left and right hands holding Shift every time the key falls on the opposite side of the keyboard. It would seem that this is an ideal case for using CapsLk, but I've long remapped that key to Ctrl because of the scarcity of its use and potential for accidental triggering.
I found this related question but it deals more with enforcing the habit than the question of how to actually type efficiently using the opposite hand to hit modifier keys.
As the question appears to be targeted towards bash command lines, you can use Control-A Meta-U to capitalize the first word of the line, useful for typing
env_var=value some_command ...
prior to converting it to
ENV_VAR=value some_command ...
Instead of making CAPS LOCK an additional CTRL, you could simply swap CAPS LOCK and LEFT CTRL.