Matlab GUI keypress function changes after a button press function is executed!!!

Hi,
I am having an issue with GUI keypress function. I have a GUI made via Guide. I also created a keypress function for the GUI to detect right and left arrow keys. It works fine when I run the GUI code and try pressing any keys.
However, the next thing I do in the GUI is to press a button to load a file and do some math with the data and eventually plot two graphs. After the graphs show up, somehow the keypress function does not work anymore. When I try to press any key the command window is active and I type there. The GUI window does not detect any keypress anymore.
Why does the keypress functionality change after I load the data? Do I have to add anything specific at the end of the button press function?
Please advice me.
Sujay.

Answers (1)

The "plot two graphs" part might be responsible. The default cla() that is done when you plot without "hold off" clears the axes callbacks as well.
Sometimes the easiest approach is just to add the callback back in after you finish plotting.

2 Comments

Thanks for your answer. I was also thinking the same way. Could you please explain a bit more on, what you mean by: "add the callback back in after you finish plotting".
ax = gca;
KPF = get(ax, 'KeyPressFcn');
... do the plotting
set(ax, 'KeyPressFcn', KPF);

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Asked:

on 13 Mar 2017

Commented:

on 13 Mar 2017

Community Treasure Hunt

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

Start Hunting!