How can I execute a script with the evalin command?

I want to execute a script in the base workspace, so I use
evalin('base', preparedata_v1)
The following error occures
Attempt to execute SCRIPT preparedata_v1 as a function:
\\..Pathofthescriptmfile...
Has anyone an idea, why matlab isn't running the scipt properly and how it can be done? Thanks in advance, -Fabian

5 comentarios

Fabian Gock
Fabian Gock el 19 de Sept. de 2017
There is no function with the same name, shadowing the script
Stephen23
Stephen23 el 19 de Sept. de 2017
Editada: Stephen23 el 19 de Sept. de 2017
"How can I execute a script with the evalin command?"
Ugh.... why why Why WHY?
Why do you want to mix two awful ways of writing code (scripts and evalin) into something totally unmanageable?
Use Functions!!!!!!!!!!
Pass data. Avoid scripts.
Fabian Gock
Fabian Gock el 19 de Sept. de 2017
Hm, I will turn it into a function then..
Fabian Gock
Fabian Gock el 19 de Sept. de 2017
thanks for the quick respond
Fabian Gock
Fabian Gock el 19 de Sept. de 2017
With the script, I wanted to create some variables in the base workspace when I click a button on the gui

Iniciar sesión para comentar.

 Respuesta aceptada

Hey Fabian,
The issue is that you are calling the script when you should be passing its name as an input argument to "evalin". Rather than this:
evalin('base', preparedata_v1)
you meant to do this:
evalin('base', 'preparedata_v1')
But Stephen really is correct. Better to call a function and use assignin than have a separate script and use evalin. That way all the code is controlled by the GUI. Also, there are some instances where you absolutely must put some data in the base workspace (especially when dealing with Simulink, or if you're trying to facilitate debugging), but it is often not necessary. If you are just looking to share data around the GUI, consider alternatives.
-Cam

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 19 de Sept. de 2017

Respondida:

el 19 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by