How to run a script with spaces in its name?

I store my script in 'My Script.m'. Is there a way to call that script without changing it to 'My_Script.m'? Thanks.
>> run 'My Script'
??? Error using ==> run at 69
Error using ==> evalin
Undefined function or method 'My' for input arguments of type 'char'.

2 comentarios

Andreas Goser
Andreas Goser el 12 de Oct. de 2011
Walter is correct, but can you tell us what the need is to do this?
Hong
Hong el 13 de Oct. de 2011
Thank all for your answers. I was just curious about the syntax, nothing's particular.

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Oct. de 2011

2 votos

No, you cannot do that, not even using run(). Script file names and function file names are required to use the same semantic rules as MATLAB identifiers: must begin with a letter (upper or lower case English alphabet), which can then be followed by any combination of digits, underscore, or upper or lower case English alphabet letters, and the total name length must be at most 63.
You could read the contents of "My Script.m" in to a string and then eval() the string, maybe.

Más respuestas (1)

Daniel Shub
Daniel Shub el 12 de Oct. de 2011

0 votos

I am not sure why you would want to do this, but you could probably overload run to take in the string with the space, copy that file to a temporary file without a space, run the temporary file, and then delete the temporary file. You would probably need to do some error catching, so you do not leave orphaned temporary files.
While it can probably be done, I don't see why you would want to.

1 comentario

Walter Roberson
Walter Roberson el 12 de Oct. de 2011
I suspect, though, that if you did that (or did my eval() solution) that the return value of mfile() might be different than it would otherwise be.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 12 de Oct. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by