MATLAB: Can a function inside a parent code access the full workspace of that parent code

functionloading variablesworkspace

I have a child function being called inside the original code. Can I have the function be able to access all of the variables (workspace) from the original code? If so, how?

Best Answer

A nested function can access the variables stored in the workspace of its caller function:
function x = outer_function(a,b)
x = inner_function;
function y = inner_function
y = a + b;
end
end
>> outer_function(2,3)
ans =
5