I have written a function using matlab as follows.
function xout= testfunc(b)
xout = b;
end
I executed this function by giving an value for b as follows.
addpath ('C:\Users\vish\docs\copy');% this is the place of the file location
testfunc(5);
This gives me a variable in my work space ans which is equal to 5,which is the general variable once after all functions are evoked.But the problem is,even though the function is executed properly, when try to use the variable xout it gives the following error message.
addpath ('C:\Users\vish\docs\copy');
testfunc(5);
varout
Undefined function or variable 'varout'.
Any help is highly appreciated.
xoutas it is mentioned in the textual description above.xoutis only locally defined within your functiontestfunc. You can name these variables whatever you like they are (in general) not visible outside your function. Therefore you'd have to call it likexout = testfunc(5)(if you want to use the same variable name, which is possible).xout. The variable goes out of scope at the end of the function. The return value is copied tov = testfunc(5);or toans. You may want to read the Matlab primers. Even experienced programmers starting with Matlab should read this.