Function control with reference to GUI

조회 수: 3 (최근 30일)
Michael ten Den
Michael ten Den 2012년 5월 20일
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