필터 지우기
필터 지우기

How to define a workspace variable in a function?

조회 수: 2 (최근 30일)
HARINI R
HARINI R 2021년 8월 21일
댓글: John D'Errico 2021년 8월 21일
I have a numeric tables that i imported in matlab workspace. I am writing a function called Myfunc in which i have to use the workspace variables (imported table) for a calculation. Then, i call this Myfunc from my main function file (Myfunc_main). My doubt is, how do i define this workspace variable in my main function?
  댓글 수: 2
Stephen23
Stephen23 2021년 8월 21일
The neatest, easiest, simplest, and by far the most efficient approach is to pass data as input/output arguments:
The MATLAB documentation clearly describes passing data as input/output arguments as "best practice".
Did you try passing the data as input/output arguments?
John D'Errico
John D'Errico 2021년 8월 21일
Exactly. You do not want to somehow magically create that variable in some other MATLAB workspace. That is an extremely inefficient way to do it, and is likely to cause many problems down the line when you try to debug code.
Instead, just return the variable as an output argument of your function. This is both trivial to do, and an efficient way to write it.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by