- 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.
some variables doesn't exist in handles after exiting callback function
3 次查看(过去 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'
0 个评论
回答(1 个)
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:
7 个评论
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
2015-9-30
But your handles.x is not an edit text box. Your edit text box is handles.uiVarName
另请参阅
类别
在 Help Center 和 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!