Return them as output arguments. The simplest solutions are usually the best.
" before in the GUI there was evalin(), and assignin() function ..."
Note that making variables magically appear and disappear in other workspaces is one way that beginners force themselves into writing slow, complex code. Passing variables as input/output arguments is much more efficient.