I have a simple question, although it's harder than it seems; I couldn't find the answer on the interwebs :O
I'm writing a script in Matlab. What I want to do is the following:
How do I do this? How can I say to Matlab: When I press esc, do this...
Thanks for your time guys!
EDIT: It's no option to implement something which awaits the keypress. Im writing a script for a driving car. It just has to drive around basically, but when I press esc for example, it should stop driving. So the script just has to run, untill I press the esc key; then the script has to pause.
KeyPressFcn
is good because it forces you to write event-driven code. Which is generally a good idea! However, if KeyPressFcn
doesn't seem right for you, for example if you must keep running in a loop, and you just want to poll whether a key has been pressed, I found this solution buried in the matlab website:
get(gcf,'CurrentCharacter')
Then you could set this property to a blank, and poll it as required. e.g:
finish=false; set(gcf,'CurrentCharacter','@'); % set to a dummy character while ~finish % do things in loop... % check for keys k=get(gcf,'CurrentCharacter'); if k~='@' % has it changed from the dummy character? set(gcf,'CurrentCharacter','@'); % reset the character % now process the key as required if k=='q', finish=true; end end end
This worked well for me in 2014b. The downside is that the graphics window needs to be focused to receive the key events.
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.