Matlab GUI keypress function changes after a button press function is executed!!!
Show older comments
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)
Walter Roberson
on 13 Mar 2017
0 votes
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
sujay Ray
on 13 Mar 2017
Walter Roberson
on 13 Mar 2017
ax = gca;
KPF = get(ax, 'KeyPressFcn');
... do the plotting
set(ax, 'KeyPressFcn', KPF);
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!