How do I get MatLab to respond to keyboard?

12 次查看(过去 30 天)
I would like to run some code if the letter "r" is pressed on the keyboard. How would I do this? And what syntax would be used? And should I store the code I would like to run in a separate editor?
Thank you!

回答(1 个)

Walter Roberson
Walter Roberson 2016-10-19
  7 个评论
Emily Smith
Emily Smith 2016-10-20
sorry for all the questions by the way, I'm new at this
Walter Roberson
Walter Roberson 2016-10-21
In the editor for callbackfunction.m change the code to be
function callbackfunction(src, event)
if strcmp(event.Character, 'r')
imshow('TheImageToDisplay.jpg');
end
Then in the code that needs to tell MATLAB to allow that callback to be used, put in
set(gcf, 'Windowkeypressfcn', @callbackfunction)

请先登录,再进行评论。

类别

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