Function control with reference to GUI

3 views (last 30 days)
Michael ten Den
Michael ten Den on 20 May 2012
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

Answers (1)

Michael ten Den
Michael ten Den on 20 May 2012
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

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!