Issues with other scripts accessing workspace variables

조회 수: 7 (최근 30일)
Cami
Cami 2025년 3월 24일
편집: Stephen23 2025년 3월 25일
Hello,
I have pre-defined a set of variables in one .m file and written a function in another file that needs to use some of these variables. I ran the variables file, can see the variables stored in the workspace, and yet when I try to run the functions they do not recognize the variables. Any ideas?
I have attached a picture. It shows the variables storing file, the workspace with said stored variables, and an error that appears in the command window when the functions try to call the workspace variables.
Thank you.
  댓글 수: 1
Stephen23
Stephen23 2025년 3월 25일
편집: Stephen23 2025년 3월 25일
Calling CLEAR ALL is an example of:
Do not write CLEAR ALL at the top of everything that you write. It will not help you.

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

답변 (1개)

dpb
dpb 2025년 3월 24일
<function>s have an independent workspace from the base workspace. See <Base and Function Workspace> and the reference linked to there that shows best practice is to pass arguments to your functions.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by