Using a variable calculated in a function in the workspace
2 次查看(过去 30 天)
显示 更早的评论
I have a function which I am calling with 4 input variables.
I have a single output variable that I want to use after the function is finished.
FEM_Rechnung(D_klein, R_mitte,job,index);
to call the function and the function looks like this:
function [jobname]=FEM_Rechnung (D_klein, R_mitte, job, index)
I thought doing it this way the variable "jobname" is automatically returned to the workspace after the function is done. But I can't use it. I've seen ways with assignin or evalin but as far as I read those things come from the deepest levels of hell.
How can I use the "jobname" variable?
0 个评论
采纳的回答
Stephen23
2021-3-11
编辑:Stephen23
2021-3-11
"I thought doing it this way the variable "jobname" is automatically returned to the workspace after the function is done."
Nope, nowhere in the MATLAB documentation does it state that.
"How can I use the "jobname" variable?"
Have you tried calling the function with an output argument, just like the introductory tutorials show?:
myout = FEM_Rechnung(D_klein, R_mitte,job,index);
%^^^^^^^ you need to assign the output to a variable.
Note that the names of variables used inside a function are (and should be) unrelated to the names used outside the function. You might use the same name, but that is simply coincidence and of no importance to MATLAB.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!