Key press in MATLAB

조회 수: 14 (최근 30일)
Nick Matin
Nick Matin 2017년 1월 11일
댓글: Walter Roberson 2019년 9월 5일
I have a main script in MATLAB in which I am calling four different functions each has been defined in a separate script.
function[] = main()
[par_1] =function_1(inp_1);
[par_2] = function_2(inp_2);
[par_3] = function_3(inp_3);
end
Now I want to define here that while for example function_1 is being called and is running, by pressing a key, for example 'esc', function_1 stops and return and function_2 starts running and so on. I don't know how to do this in MATLAB.

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 11일
In MATLAB, you can only do that with the cooperation of the function itself. You would define a callback such as a figure WindowKeyPressFcn callback, that would set a "key was pressed!" flag in a common space, and the functions being run would have to periodically check whether the flag was set and voluntarily exit if it found the flag set.
  댓글 수: 5
Thomas
Thomas 2019년 9월 4일
Need a comma after that first line's 'UserData'
Walter Roberson
Walter Roberson 2019년 9월 5일
You are correct, Thomas, it should have been
set(gcf, 'Windowkeypressfcn', @(src, event) set(src, 'UserData', true) )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by