How to declare Universal variable in GUIDE?

2 ビュー (過去 30 日間)
Reed Torres Torres
Reed Torres Torres 2018 年 4 月 16 日
編集済み: Stephen23 2018 年 4 月 16 日
I'm creating a GUIDE app that is supposed to load data and be able to plot 8 different regressions based off the data and display the plot in the GUI. The data is loaded by entering the filename into an editable text box, and clicking a button will read the data and put it into a matrix (using dlmread function). I'm not having trouble with this part. I then assign the x and y values to separate variables. Next, for example, clicking the linear regression function should plot the X vs Y. However, I can't get it to work because the x and y data variables are in the load button callback. In other words, I don't know how to use a variable created in one callback in another callback. Is there a way to make a global variable?
  1 件のコメント
Stephen23
Stephen23 2018 年 4 月 16 日
編集済み: Stephen23 2018 年 4 月 16 日
"Is there a way to make a global variable?"
Yes, but using global variables is a bad way to write code. Avoid using globals:
It is simple and much more reliable to use the standard methods for passing data between callbcaks, such as guidata, nested functions, etc.:
Search this forum for guidata for many examples of how to do this.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 16 日

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by