MATLAB: Function executing a Script – Intrested in Scripts Output

function call script

Hello,
I'm trying to combine my work in a simple function, which calls some Scripts. My Problem is that the OutputVariables won't show up in the Workspace (probably because functions use a different workspace than Scripts/CommandWindow). I want to use the function to declare a (global) variable that should be used in all Scripts. In the End I am interested in the Variables set in the Scripts.
My Function looks like:
function testfunction(x)
global d;
d = x;
Script1
end
and the Scripts do all kind of simple things:
%Script1
global d;
A = zeros(2,2);
A(1,1) = 3*d;
Now my Problem is that the Matrix A would not show up (in the WorkSpace) after calling 'testfunction(1)'. But if i worked in the CommandWindow with:
global d;
d = 3;
Script1
It would work as inteded. Obviously i run more Scripts and more complex things inside the Scripts. Reworking all Scripts as functions is the least thing i would like to do. I debuged and it confirmed that everything works well up to the point where the function ends. Then all the Variables I am interested in get cleared out of the workspace.
Thanks in Advance

Best Answer

See Jan's comments above, but for your problem, use this:
evalin('base','Script1')