0

In my loadsignals.m script has a function which runs a script test.m to create variables in base workspace.

Why variables are not created in base workspace ?

How can i create variables in base workspace I do not want to use assignin function ?

loadsignals.m :--

function loadSignals(VarName)

  ... do some work ...

  run(test);

end

test.m :--

a = uint8(10);
b = uint8(20);
c = uint16(0); 
1
  • You call the script from a function, the variables have the functions scope. You already have a solution (assignin), what is wrong with this solution? Commented Aug 6, 2015 at 8:12

1 Answer 1

2

When you call a script from a function, the script uses the function workspace. Therefore the created variables are not stored in the base workspace unless you do it explicitly. This can be done with assignin as already mentioned.

One reason of not using assignin could be that you don't want to modify the script test.m itself. To circumvent this, you can use evalin to execute test.m in the base workspace. The variables are then getting stored in the base workspace as well.

evalin('base','run(''test.m'')');

Note that run(test) may not work because the file test.m is a script and not a function. You can use run('test.m') instead. To have the ' in a string, you need to write it twice '' like shown in the second argument of evalin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.