필터 지우기
필터 지우기

setappdata and getappdata issues in matlab gui

조회 수: 3 (최근 30일)
Ria3242
Ria3242 2016년 9월 29일
댓글: Ria3242 2016년 10월 5일
I want to share a numeric count between two callbacks in such a way that at first the count gets incremented and 'set' by setappdata after some processing. Then I push another button and want to get the incremented value through getappdata. My getappdata statement is not getting the value in a new variable.
My code is:
handles.output=hObject;
password_count = getappdata(UserRegistrationPhase,'CurrentPasswordCount');
%then some code work with password_count
setappdata(UserRegistrationPhase,'CurrentPasswordCount',password_count);
in the other pushbutton callback:
handles.output = hObject;
current_pass = getappdata(UserRegistrationPhase,'CurrentPasswordCount');
switch current_pass
case 1
%and so on with the code
When I debug step-by-step, the getappdata line does nothing, and does not give the new value of incremented variable i.e. password_count. Getting confused. Im in the need of help for this. Thanks in advance.
  댓글 수: 3
Ria3242
Ria3242 2016년 10월 5일
this is my GUI name. i guess Im putting it the wrong way am I?
Adam
Adam 2016년 10월 5일
If it is the GUI name then
handles.UserRegistrationPhase
should be the handle to the GUI itself.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2016년 9월 29일
Ria3242 - since you are using GUIDE to create your GUI, then just use the handles structure to store the password count. Every callback has access to this structure and receives an updated version whenever the callback is called. For example, in your first set of code you would do
password_count = 0;
if isfield(handles,'CurrentPasswordCount')
password_count = handles.CurrentPasswordCount;
end
%then some code work with password_count
% save the updated password count
handles.CurrentPasswordCount = password_count;
guidata(hObject,handles);
Then, in your push button callback just do
password_count = 0;
if isfield(handles,'CurrentPasswordCount')
password_count = handles.CurrentPasswordCount;
end
Try the above and see what happens!
  댓글 수: 1
Ria3242
Ria3242 2016년 10월 5일
Yes Sir I tried it. And it really works! Thank you so much for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by