2013-07-27 6 views
0

이것은 MATLAB GUI입니다. 그리고 while 루프를 돌리고 있습니다. 그러나 루프에서 나는 다른 콜백 인 키보드 입력을 사용해야합니다. 방법이 있습니까? 또는 루프에있는 동안 해당 콜백을 실행할 수 있습니까?MATLAB GUI에서 루프의 콜백 함수

참고 : 나는

+0

while 루프 내부에서 키보드 입력이 while 루프 내부의 다양한 함수를 호출하기를 원한다는 것을 의미합니까? – voxeloctree

+0

이들은 GUIDE – Chandough

+0

Ahhhhh에 의해 생성 된 GUI에 대한 콜백 함수로, 생각한 것과는 상당히 다릅니다. 설명 주셔서 감사합니다. – voxeloctree

답변

1

예,이 가능 GUIDE 사용하고 있습니다. 키 누르기 콜백에서 루프에있는 콜백으로 문자 데이터를 가져와야합니다. 이를 수행하는 한 가지 방법은 figure guidata를 사용하는 것입니다. 예를 들어

, 루프는 버튼 콜백에서 실행하면 다음과 같은 사용할 수있는 그림에의 키를보고 싶다면 :

버튼 콜백

% --- Executes on button press in pushbutton1. 
function pushbutton1_Callback(hObject, eventdata, handles) 

fig = get(hObject,'Parent'); 
for i=1:1000 
    pause(0.01); 
    % Get the latest guidata 
    handles = guidata(fig); 
    if isfield(handles,'KeyData') && ~isempty(handles.KeyData) 
     fprintf(1,'Pressed : %s\n', handles.KeyData.Character); 
     % Clear the keydata we have now handled. 
     handles.KeyData = []; 
     guidata(fig,handles); 
    end 
end  

그림 키 누르기 콜백

% --- Executes on key press with focus on figure1 and none of its controls. 
function figure1_KeyPressFcn(hObject, eventdata, handles) 

% Store the keypress event data for use in the looping callback 
handles.KeyData = eventdata; 
guidata(hObject,handles); 
+0

for 루프는 while 루프에 있습니까? – Chandough

+0

@Chandough - 예, 방금 작동하는 방법을 보여주기 위해 for 루프로 작성했습니다. 최신 Guidata 가져 오기 코드가 필요합니다. – grantnz

+0

방금 ​​해 보았습니다. 그것은 작동하지 않았다. – Chandough