Filter löschen
Filter löschen

How do I get MatLab to respond to keyboard?

12 Ansichten (letzte 30 Tage)
Emily Smith
Emily Smith am 19 Okt. 2016
Kommentiert: Walter Roberson am 21 Okt. 2016
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 Kommentar
Adam
Adam am 19 Okt. 2016
Take a look at KeyPressFcn in Figure properties.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 19 Okt. 2016
  7 Kommentare
Emily Smith
Emily Smith am 20 Okt. 2016
sorry for all the questions by the way, I'm new at this
Walter Roberson
Walter Roberson am 21 Okt. 2016
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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Desktop finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by