Undefined variable in workspace problem

12 ビュー (過去 30 日間)
Máté Torma
Máté Torma 2021 年 11 月 25 日
編集済み: Stephen23 2021 年 11 月 25 日
Hello everyone,
there's a seemingly simple problem that I can't solve unfortunately. I'd like to run the following, very simple code:
function measVal = dataIn(step)
measVal = measurementValue(step,1);
end
where measurementValue is an n x 1 double array already loaded in my workspace. But when I try to run the code, I get the following error:
Undefined function or variable 'measurementValue'.
What could be the problem here? Thank you in advance for your help.
  2 件のコメント
KSSV
KSSV 2021 年 11 月 25 日
What is measurementValue? Is it a function or variable? It seems it is a function, try to keep this function in the same pwd.
Máté Torma
Máté Torma 2021 年 11 月 25 日
No, it's an array filled with double values and loaded in the workspace:

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2021 年 11 月 25 日
編集済み: Stephen23 2021 年 11 月 25 日
"where measurementValue is an n x 1 double array already loaded in my workspace."
I guess you mean that it is loaded into the base workspace (every function has its own workspace):
Because you did not pass that variable as an input argument to that function, it is NOT in that function workspace.
"But when I try to run the code, I get the following error: Undefined function or variable 'measurementValue'. What could be the problem here?"
Very simple: the variable is not in the function workspace.
Simplest and most efficient solution: pass it as an input argument.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by