GUIDATA updating "handles" in GUIDE with nested functions
1 次查看(过去 30 天)
显示 更早的评论
Attached you can find a simple GUIDE with 2 push buttons:
Button #1 plots a sine graph.
Button #2 adds a "movable" vertical line to the graph.
Everything works fine and I can drag vertical line as desired (Thanks to Geoff and Walter)
What I'm trying to do now is to record x-position of vertical line (x_history) as I move it, and save this x_history to handles (via guidata) such that if I stop moving the line (mouse-up) and then resume moving the line (mouse-down and mouse-move) I can restore previous x_history from handles (via guidata).
The problem I'm facing is that every time I stop moving the line and go mouse-up, handles resets(!) the x_history field (removes the field), so I loose the previous record of x_history when I resume mouse-down and move the line.
What am I missing here?
Alborz
0 个评论
采纳的回答
Jan
2017-8-6
编辑:Jan
2017-8-6
This is a confusing mixture of storing the handles struct in two figures by guidata, using handles from the inputs of the callbacks (where it is a static copy of the contents from this struct at the time of the creation of the callback), and the common using of local variables in nested functions. This is more complexity than you require.
Decide for one mechanism to share the handles struct, e.g. in the figure's ApplicationData by using guidata and prefer the figure, which contains the activated object. Then insert this in each callback:
function XYZ_Callback(hObject, EventData, handlesFromInput)
handles = guidata(hObject);
...
guidata(hObject, handles);
end
Convert the nested functions to "non-nested normal" (how is it called?) function and use the input hObject.
In addition the guidata concern the figure, which contain the figure with the two buttons, not the figure, which contains the diagram and the moved line. Better keep your data locally in the figure, which is processed.
By the way: I could not reproduce your observation:
The problem I'm facing is that every time I stop moving the line and go
mouse-up, handles resets
How and where do you observe this?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!