필터 지우기
필터 지우기

some variables doesn't exist in handles after exiting callback function

조회 수: 2 (최근 30일)
Wenjie Wu
Wenjie Wu 2015년 9월 29일
댓글: Walter Roberson 2015년 9월 30일
MATLAB 2015a
Q1:
For example, in a callback function of a text box (Note that: I made the function name different from the 'varName')
function uiVarName_Callback(hObject, eventdata, handles)
handles.varName = get(hObject,'String');% get varName
guidata(hObject,handles); % update gui handles
When the function exits, I cannot find varName in the handles(which I think is a master handle across the board).
In other callback functions, if I call handles.varName,
it says 'Reference to non-existent field'
Q2: How can I extract only the value of a textbox, for example, uiVarName. When I type uiVarName without a ;, then it returns as follow, which is not value in the ext box.
UIControl (uiVarName) with properties:
Style: 'edit'
String:
BackgroundColor: [0.9400 0.9400 0.9400]
Callback: @(hObject,eventdata)sharp_gui('uiMinPkWidth_Callback',hObject,eventdata,guidata(hObject))
Value:
Position: [0.0500 0.1163 0.1365 0.4419]
Units: 'normalized'

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 30일
Q2: You appear to be using R2014b or later, so you can use
uiVarName.Value
Note that the Value of a uicontrol('Style','text') has not been assigned any meaning; see http://www.mathworks.com/help/matlab/ref/uicontrol-properties.html#property_value
If you are looking for the text that has been put in the text box then
uiVarName.String
Q1:
  • guidata(hObject,handles) would update the guidata (handles) structure associated with the figure that hObject belongs to. If you have multiple figures then that is not necessarily the same place that other handles references are getting the data from.
  • when you use guidata() to update the master "handles" structure, other routines will not observe the update until they request the current copy of the data. If you are using GUIDE then the update should show up the next time they are called, but if you have one callback routine call another callback routine that updates the handles then the first routine will not know.
  댓글 수: 7
Adam
Adam 2015년 9월 30일
You can tell very quickly whether the function is even being called or not by either putting a disp( 'Something or other' ) statement in it and seeing if that appears in your command window or just putting a breakpoint in.
That seems like the key question. Your syntax with respect to handles looks fine, but if the function never gets called then that would be the simplest explanation why the field does not exist.
Walter Roberson
Walter Roberson 2015년 9월 30일
But your handles.x is not an edit text box. Your edit text box is handles.uiVarName

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

카테고리

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