[Using saved variables] Unable to use saved variables in my functions. Could be a problemo fo Global/local Variables.

1 回表示 (過去 30 日間)
I have imported my data in matrix form naming this variable as "p". I have then saved it as p.mat and at the beginning of each session I recall it in my workspace. I would like to use it inside my functions but as soon as i run my function codes i get that "p" is an undefined variable. I think it is a problem of local and global variable. I tried to set p as global variable in order to pass it into my function codes but without success. (I have written on the command window "global p" but I do not think it is that easy). The description of global (help global) does not provide any interesting answer.
Now my codes are working because in each function I use "myimport" which is a script that creates p everytime.
  1 件のコメント
Stephen23
Stephen23 2017 年 4 月 23 日
編集済み: Stephen23 2017 年 4 月 23 日
The MATLAB documentation explains how to pass data between workspaces:
Note that the documentation clearly states Best Practice: Passing Arguments. Using globals is a bad practice because it makes buggy code that is almost impossible to debug:

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 4 月 23 日

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by