Variables become undefined although they are saved in Workspace

I read XML file using GUI pushbutton, extract some data, and do some manipulations for them. The thing is although I save the required variables to workspace (using assignin), I can't use them outside the pushbutton callback function for further manipulation because matlab tells me 'undefined variables'! any suggestions? Thanks

6 件のコメント

Adam
Adam 2016 年 1 月 13 日
It would help if you show some code. I never use assignin as it is generally a very bad idea and a situation I have never found any need for, but in theory it should do what you say, in practice it depends on your actual code.
Mus'ab Ahmad
Mus'ab Ahmad 2016 年 1 月 13 日
I attached the whole callback function, none of the variables you see inside the function is working outside it! I thought using assignin would help, but still having the same error.
Adam
Adam 2016 年 1 月 13 日
You haven't attached anything yet so far as I can see.
Mus'ab Ahmad
Mus'ab Ahmad 2016 年 1 月 13 日
Don't know if you can find the attachement
Adam
Adam 2016 年 1 月 13 日
You need to make sure you click 'Attach File' after clicking the paper clip and choosing your file. A lot of people (including myself sometimes) miss that and think it is attached just through choosing the file under the paperclip.
Mus'ab Ahmad
Mus'ab Ahmad 2016 年 1 月 13 日
Hope it is attached now

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

 採用された回答

Ilham Hardy
Ilham Hardy 2016 年 1 月 13 日

0 投票

Did you also define the workspace location?
e.g.
assignin('base','your_variable_name',your_variable_value);

4 件のコメント

Mus'ab Ahmad
Mus'ab Ahmad 2016 年 1 月 13 日
Yes I did, and can see the value in the workspace, that's why I wonder why I can't use it anywhere in the code
Ilham Hardy
Ilham Hardy 2016 年 1 月 13 日
I assume by "use it anywhere", means anywhere else in your GUI (another callback)?
GUI has its own workspace. When you call the variable from your callback, it only search on its local workspace. You need to re-define your variable before you can call it.
e.g.
Let myvar become your base workspace variable. Before you can use myvar in your callback use:
myvar = evalin('base','myvar');
The above code will assign myvar from the base workspace, to local workspace variable, myvar.
Mus'ab Ahmad
Mus'ab Ahmad 2016 年 1 月 13 日
編集済み: Mus'ab Ahmad 2016 年 1 月 13 日
Yes this what I meant; using it in another callback. It works now, thanks a lot.
Adam
Adam 2016 年 1 月 13 日
If you just want to share data between callbacks then you shouldn't go through the base workspace at all, but I guess it works for you for now.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeWorkspace Variables and MAT Files についてさらに検索

質問済み:

2016 年 1 月 13 日

コメント済み:

2016 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by