Using a variable calculated in a function in the workspace

2 Ansichten (letzte 30 Tage)
Patrick Benz
Patrick Benz am 11 Mär. 2021
Bearbeitet: Stephen23 am 11 Mär. 2021
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?

Akzeptierte Antwort

Stephen23
Stephen23 am 11 Mär. 2021
Bearbeitet: Stephen23 am 11 Mär. 2021
"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.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by