MATLAB: How to create variables in the command prompt space using a function

functionsMATLABpassing value among functions

I have a problem with passing a value of a variable (say X)in one function (function A) to another function (function B), because i can't pass the particular function arguments of the first function(A) inside the function B. So what I am trying to do is this. I can get the values of that variable(X)to the command prompt. Then I am trying to pass those values to the second function(B) as an argument. It's hard to put the real problem in here. I will give an example the following is my function A.
function [X] = funcA (inputsToA)
X; //this is the required variable to be passed to function B
end
my second function is as follows
function [outB] = funcB (inputsToB)
.
.
X = funcA (inputsToA) //i am trying to get X here, BUT 'inputsToA' has to be //generated in the function and it's not possible due to some reasons.
end
So what I am trying to do is this. First get the value of X to the command prompt simply as follows (by removing the semicolon at X)
function [X] = funcA (inputsToA)
X //remove the semicolon
end
and then try to get that value passed to the function B as follows.
function [outB] = funcB (inputsToB,X) //trying to get the value X end
So please be kind enough to show me a way to get this done…and apologize for the incompleteness of the problem. And I am new to MatLab programming. Thanks .

Best Answer

First of all, comments in MATLAB are given by %, not //.
Second, which function are you calling first, and from where, and what are you passing in to that function? To pass a value to a function, you just pass it!
function [X] = funcA (inputsToA)
X = inputsToA;
funcB(X) %Pass X to function B
end
You are going to have to put a simplified version of the real problem so that we can understand what you want, I think. Start with two functions, funcA and funcB. Now what? You call funcA from the command line and need funcA to call funcB? Then what?