Retrieve data from a guidata from another file

2 ビュー (過去 30 日間)
Ali
Ali 2022 年 9 月 30 日
コメント済み: Ali 2022 年 9 月 30 日
I have a counter that increment each time i click on a pushbutton and the value is stored in a guidata which works it gives me the wanted value. (The function that increments is in the same file as the gui)
But i want to get the value form the guidata in another file as a condifition for a if but i always return me this error :
Undefined variable "handles" or class "handles.X".
Error in kgexec4n (line 67)
if get(guidata(hf,handles.X),'Value')==1
Error while evaluating uicontrol Callback
and here is the gui code with the function and the pushbutton
function h0=kgui4n
%KGUI4N construction de la boite de dialogue pour KGEXEC4N
%CAVIAR2, © ALSTOM + OL 1999/12-2003/03
blanc=[1 1 1];
gris=blanc*0.75;
%figure
h0=figure(...
'Units','characters',...
'DefaultUicontrolUnits','characters',...
'Color',gris,...
'DefaultUicontrolBackgroundColor',gris,...
'HandleVisibility','callback',...
'IntegerHandle','off',...
'MenuBar','none',...
'Name',ch00{lg},...
'NumberTitle','off',...
'Position',[100 30 110 25],...
'Resize','on',...
'Tag','NormeDlg',...
'WindowStyle','modal',...
'ToolBar','none');
%% Pushbutton
handles.X = 0;
handles.button = uicontrol(h0,...
'Callback',@buttonCB,...
'Position',[10 0.5 9 2],...
'String','count',...
'Tag','count');
guidata(h0, handles);
%%%%%%%%%%%%%
function buttonCB(ButtonH, EventData)
handles = guidata(ButtonH);
handles.X = handles.X + 1;
if handles.X > 3
handles.X = 0
end
guidata(ButtonH, handles)
I would like to know how i could get the value of handles.X which is stored in the guidata and use it in another file ?

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 30 日
handles_hf = guidata(hf);
if handles_hf.X.Value == 1
  6 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 30 日
You need some way of getting the handle of the figure created by kgui4n . For example you might do
hf = findobj(groot, 'type', 'figure', 'tag', 'NormeDlg');
handles_hf = guidata(hf);
if handles_hf.X == 1
etc
end
Ali
Ali 2022 年 9 月 30 日
thank you it made the trick

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by