MATLAB: Calling a function from another function

MATLABmatlab function

The first function is as below:
function my_first_function1(input,b)
c = input*b;
absx = c;
absx
end
The second function calling the first function is below:
function my_first_subfunction(a)
input = 2;
d = my_first_function1(input,b);
out = d +a;
out
end
Error:
>> my_first_subfunction(a)
Unrecognized function or variable 'b'.
Error in my_first_subfunction (line 3)
d = my_first_function1(input,b);

Best Answer

my_first_function1( ) doesn't return any value to the caller. To return a value you use this syntax:
function absx = my_first_function1(input,b)
c = input*b;
absx = c;
absx
end
my_first_subfunction( ) uses variable b before it is defined. Examine the code for this function and you will see that there is nothing in the function that defines b before it is used as an input argument to another function.