What is the meaning of "global" in matlab GUI?

1 回表示 (過去 30 日間)
Epri Pratiwi
Epri Pratiwi 2020 年 8 月 13 日
コメント済み: Epri Pratiwi 2020 年 8 月 13 日
What is the purpose of using these global function? Why I have to use this?
function testGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% guidata(hObject, handles);
% set(findall(handles.uipanel1,'-property','enable'),'enable','on');
% set(handles.uipanel1,'visible','on');
% set(findall(handles.uipanel6,'-property','enable'),'enable','off');
% set(handles.uipanel6,'visible','off');
% set(findall(handles.uipanel7,'-property','enable'),'enable','off');
% set(handles.uipanel7,'visible','off');
global setting
global List
global i
setting=0;
i=1;
List=cell(15,1);
set(handles.text27,'String','Welcome to Music Listening Test');
  3 件のコメント
Stephen23
Stephen23 2020 年 8 月 13 日
編集済み: Stephen23 2020 年 8 月 13 日
"Why I have to use this?"
You don't have to.
Using global variables makes accessing variables slow, liable to bugs, and difficult to debug.
The MATLAB documentation lists the recommended ways of passing data within a GUI:
The MATLAB documentation also advises "Use global variables sparingly, if at all."
Epri Pratiwi
Epri Pratiwi 2020 年 8 月 13 日
nice info!

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by