Using a variable calculated in a function in the workspace

2 visualizaciones (últimos 30 días)
Patrick Benz
Patrick Benz el 11 de Mzo. de 2021
Editada: Stephen23 el 11 de Mzo. de 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?

Respuesta aceptada

Stephen23
Stephen23 el 11 de Mzo. de 2021
Editada: Stephen23 el 11 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by