What causes MATLAB to execute pasted code automatically?
Mostrar comentarios más antiguos
Sometimes I will copy a piece of code that someone has put up in answer to a question, then paste the code into MATLAB at the command prompt. Often I will need to make a change to the code before I hit return, such as fixing a typo. Usually this works fine, but sometimes the code executes as soon as I paste it, resulting in the expected error due to the typo. If the block of code is long I usually end up pasting it into the editor, making the change, then copying and pasting into the command window to execute the code.
This is annoying, so what causes this sometimes and not other times?
Respuesta aceptada
Más respuestas (2)
Jan
el 1 de Feb. de 2011
I'm using a small function to clean the contents of the clipboard:
function cv % reminds me to Ctrl-V
Str = clipboard('paste');
Index = max(find(~isspace(Str)));
clipboard('copy', Str(1:Index));
Afterwards I can user Ctrl-V without triggering the execution. It might be more convenient to use one of Yair's tricks, the java.awt.Robot or FEX:textInject to write directly to the command prompt. But I use it too seldom to need this.
Oleg Komarov
el 1 de Feb. de 2011
0 votos
A visual example:

In the first part, if you select down to the next line, you include a carriage return, and whenever you paste to the cmd windonw the code is executed.
The second part is the tedious end-of-line selection...which once pasted stays on the cmd window until you 'enter' it.
I desume from this example that Jiro is correct.
Oleg
1 comentario
Matt Fig
el 1 de Feb. de 2011
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!