why guidata not saving handles data
古いコメントを表示
Hi,
I've inserted these 2 lines in my GUI opening function:
handles. hText = '';
handles.allLines = [];
set(gcf, ...
'WindowButtonDownFcn', {@clickFcn, handles}, ...
'WindowButtonUpFcn', @unclickFcn);
I've a code that I added 2 data 'allLines' and 'hText'
function plot2_push_Callback(hObject, eventdata, handles)
handles.allLines = findobj(gcf, 'type', 'line');
handles.hText = nan(1, length(handles.allLines));
for id = 1:length(handles.allLines)
handles.hText(id) = text(NaN, NaN, '', ...
'Parent', get(handles.allLines(id), 'Parent'), ...
'BackgroundColor', 'yellow', ...
'Color', get(handles.allLines(id), 'Color'));
end
guidata(hObject, handles);
then I would like to use it here:
function clickFcn(hObject, eventdata, handles)
a = 1;
b = handles.hText;
c = handles.allLines;
disp(a)
disp(b)
disp(c)
but looks like the handles structure does not save the data from the plot callback..
how can I solve this? Thanks.
2 件のコメント
Walter Roberson
2016 年 3 月 28 日
Does this replace your earlier question http://www.mathworks.com/matlabcentral/answers/275722-windowbuttondownfcn-cant-detect-handles-data-from-other-callbacks ?
James Ang
2016 年 3 月 28 日
採用された回答
その他の回答 (1 件)
Antoine Hurtado Huyssen
2017 年 8 月 29 日
0 投票
each time you add Something to your handles you need to update the guidata
guidata(hObject,handles);
1 件のコメント
Walter Roberson
2017 年 8 月 29 日
That is not sufficient in this situation. The user had coded
'WindowButtonDownFcn', {@clickFcn, handles}, ...
which causes a copy of the handles structure to be taken and that copy would be what would be passed to clickFcn. Using guidata() to update the master version of the handles structure would not update the copy that was saved.
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!