How to create a unique output variable name based on input variable name in function

10 views (last 30 days)
I would really like this output variable to carry the name of my input variable.
That way I can harvest a list of variables in the workspace instead of having to manually change the name of the output variable after each function call.
I hope you understand what I would like to achieve.
This is my function:
.
.
=> the output variable name is always wavelengtha
BUT I would like it to be a "unique other" output variable name, preferably wavelengtha_x (depending on my x input) or just X or something like that

Accepted Answer

Star Strider
Star Strider on 22 Oct 2014
The output variable is whatever you want to call it. You have to call it ‘wavelengtha’ internally in order for the function to return that variable as output, but ‘wavelengtha’ is only local to your ‘test’ function.
You would call the function, for instance with variables ‘x_1’ and ‘y_1’ and you want to call your wavelength ‘lambda_1’, simply call your function with:
lambda_1 = test(x_1,y_1)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!