필터 지우기
필터 지우기

Problem with my Callback function or handles values

조회 수: 1 (최근 30일)
Nimrodb
Nimrodb 2013년 3월 3일
Hi everybody, I have a problem with my function and I do not understand why.
Here is some part of my code:
handles.STANumber = 1;
handles.PanelPosition = [60 670 1098 80];
handles.AddSTA = uicontrol( 'Parent',handles.MainFigure,...
'style','pushbutton',...
'String','Add STA',...
'Tag','AddSTA',...
'Callback', {@AddSTA,handles});
handles.STANumber = handles.STANumber + 1;
....
function [handles] = AddSTA(hObject,eventdata,handles)
handles.AddSTA = hObject; % I DO NOT KNOW WHY THIS IS NEEDED. without this
% handles.AddSTA is not recognized - but all the
% other handles are recognized
handles.STANumber = handles.STANumber + 1;
My main problems are:
1. When I enter the AddSTA function the handles structure does not have AddSTA field
2. Every time I enter the AddSTA function - handles.STANumber is '1' (even though I prev' increased it) - On the same not - handles.PanelPosition is also in his default value.

답변 (1개)

Brian B
Brian B 2013년 3월 3일
편집: Brian B 2013년 3월 3일
You need to save handles back to the figure after each call, as in:
handles.STANumber = handles.STAumber + 1;
guidata(hObject,handles);
  댓글 수: 2
Nimrodb
Nimrodb 2013년 3월 3일
I tried that already. I places 1 in my main function (at the end) and got the folloiwng error:
Reference to a cleared variable hObject.
Error in SimulationMain (line 28)
guidata(hObject,handles);
and I also tried to place 1 at the end of the AddSTA function and that did not produce an error - but also did not do anything.
Walter Roberson
Walter Roberson 2013년 3월 3일
Do you have "clear all" statements in your code?

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

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by