Function control with reference to GUI

3 次查看(过去 30 天)
Hé Matlabbers,
I was struggling in Matlab and still can't solve this problem.
I have a M-File where I create this to uicontrols in a GUI.
edXi = uicontrol(ph,'Style','edit',...
'String','0',...
'Position',[200 52 100 20]);
edYi = uicontrol(ph,'Style','edit',...
'String','0',...
'Position',[150 52 100 20]);
pbLock = uicontrol(ph,'Style','togglebutton','String','Lock',...
'Units','normalized','Callback',@lock_call,...
'Position',[.1 .80 .4 .15]);
When someone press the togglebutton, the function below (written in a different m file) has to be executed. Only how do I give the reference of the 'edit' uicontrol to the function to change the string in the 'Edits' within the function?
function lock_call(hObject,eventdata)
set(edXi,'String',num2str(pos(1)));
set(edYi,'String',num2str(pos(2)));
end

回答(1 个)

Michael ten Den
Michael ten Den 2012-5-20
While writing and posting my Question some new keywords came in my head and I found my answer in a similar question.
Answer of similar question is below.
Hi,
add the handle from the uicontrol to the handles structure:
handles.edit = zeros(1, 10);
handles.edit(i) = uicontrol('style', 'edit', ...);
guidata(hObject, handles)
in the save callback you collect the entries:
entries = cell(1, 10);
for i=1:10
entries{i} = get(handles.edit(i), 'string');
end
Titus

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by