How to use a same variable to functions in Gui?

I have used the Gui to build the a programm. I would like when the user to click on menu item A, a number is stored in a variable. When the user click on menu item B, another number is stored in the same variable.
I want to use this variable in other function, in a loop. So, I'm trying that. Since now, I thank you for attention.

2 件のコメント

Shameer Parmar
Shameer Parmar 2018 年 10 月 19 日
編集済み: Shameer Parmar 2018 年 10 月 19 日
Are you sure you want to click on menu item ? OR you want to say push button of GUI?
Daniel Fonsêca
Daniel Fonsêca 2018 年 10 月 23 日
Menu item

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

 採用された回答

Daniel Fonsêca
Daniel Fonsêca 2018 年 10 月 23 日

0 投票

I got to solve that problem. I used the function "assignin()" to store a variable and its value. To acess that variable, I use "evalin"

3 件のコメント

Stephen23
Stephen23 2018 年 10 月 24 日
編集済み: Stephen23 2018 年 10 月 24 日
Magically accessing variables in other workspaces is one way that beginners write slow, complex, buggy code. It is much more reliable and more efficient to pass variables properly as input/output arguments, to use guidata, to use setappdata and getappdata, or to use nested functions:
Daniel Fonsêca
Daniel Fonsêca 2018 年 10 月 30 日
Thanks Stephen. But, do you know a way to transfer the datas without use the workspace? And, How I can clear the workspace after I use the programm?
Stephen23
Stephen23 2018 年 10 月 30 日
編集済み: Stephen23 2018 年 10 月 30 日
@Daniel Fonsêca: you change your approach to writing GUI's.
A much better approach is to pass the data to a GUI when it is called, process the data entirely within the GUI workspaces, and then return the data when the GUI closes (the waitfor command is critical here). A lot of well written code loads, processes data, and saves all without touching the base workspace at all.
See this for a simple example of passing data into and back from a GUI:
Clearing a workspace is rarely required in well written code: functions, which have independent workspaces, have their memory usage managed automatically by MATLAB.

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

その他の回答 (0 件)

カテゴリ

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

製品

質問済み:

2018 年 10 月 16 日

編集済み:

2018 年 10 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by