Using a variable calculated in a function in the workspace

조회 수: 4 (최근 30일)
Patrick Benz
Patrick Benz 2021년 3월 11일
편집: Stephen23 2021년 3월 11일
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?

채택된 답변

Stephen23
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개)

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by