Lets start with an example. Define a 1-D vector in the base Workspace:
q = [1 0 2 4 2 3 4 2 1 0 2]; % Defined 1-D vector, already in Workspace.
This is in an M-file:
function vector = r(i)
vect(i) = q(3*i-2:3*i-1);
If the function is called, for example,
r(2);
Matlab throws an error: "Undefined function or method 'q' for input arguments of type 'double'".
My question is: is there a way to make Matlab take the vector q
"for granted" when calling the function r
– q
is already defined so technically it could collected from the base Workspace to use it.
Of course the obvious solution is to add q
to the argument list:
function vector = r(i,q)
...
and then call it with
r(2,q)
Eventually I will, but I just want to know if there is something I don't know since this could be a pretty useful feature.