Serving the Quantitative Finance Community

 
User avatar
ana3a
Topic Author
Posts: 0
Joined: December 6th, 2007, 10:49 am

Matlab: data cursor in a GUI

August 21st, 2008, 12:16 pm

I have a GUI that contains an axes object.When the "data cursor mode" is on, most key presses cause the GUI to close -- very annoying.Is there a way to suppress this behavior?Oddly enough, when the "data cursor mode" is on, it is not possible to assign key press behavior to the GUI figure.
 
User avatar
spmacdonald
Posts: 0
Joined: February 18th, 2008, 5:42 pm

Matlab: data cursor in a GUI

August 21st, 2008, 1:16 pm

Not sure I entirely understand... sample code would help.It is possible to define custom behavior for the data cursor, look at the documentation for the 'datacursormode' function:fig = figure;dcm_obj = datacursormode(fig);>>> get(dcm_obj); % to get a listing of the editable properties...setting the UpdateFcn callback allows you to customize the behavior... the documentation has examples of this.What exactly are you trying to do?
 
User avatar
ana3a
Topic Author
Posts: 0
Joined: December 6th, 2007, 10:49 am

Matlab: data cursor in a GUI

August 21st, 2008, 6:39 pm

yes, i'll send the code next, don't have it right now.to answer your question >>>>i have a GUI containing an axes.i plot to this axes and i want to get the coordinates of specific points in my plot by using a data cursor.>>>>with free-standing figures, there is no problem.you go to the tool bar, click on the icon that activates the data cursor, then click at points on the plot.however, when i do this in my GUI, the GUI misbehaves:as long as the data cursor is activated, the GUI closes in response to any key press except control/shift/alt.and when this happens, the GUI closes without even going through the DeleteFcn callback.i want to find out what's causing this behavior and suppress it.by the way, at GUI creation, i use set(handles.figure,'KeyPressFcn',...) to set the key press behavior of the GUI.so my initial response to the problem was to set this callback again, after the data cursor has been activated.however, matlab won't allow this at this point.it complains that set(handles.figure,'KeyPressFcn',...) cannot be used because the data cursor mode is on.
Last edited by ana3a on August 20th, 2008, 10:00 pm, edited 1 time in total.
 
User avatar
spmacdonald
Posts: 0
Joined: February 18th, 2008, 5:42 pm

Matlab: data cursor in a GUI

August 23rd, 2008, 4:13 pm

Try doing the following:- create a new GUI with a single axes and 1 push button (open Guide, drag an axes/push button onto the canvas)- save the figure- under the 'pushbutton1_Callback' function paste:x=0:0.1:2*pi;y=sin(x);plot(x,y);datacursormode on;This simple test works correctly for me. Obviously for more complicated GUIs a little care must be taken when turning the datacursormode on, for example you should explicitly specify what axes you want the cursor for. Does this help you at all?
 
User avatar
ana3a
Topic Author
Posts: 0
Joined: December 6th, 2007, 10:49 am

Matlab: data cursor in a GUI

August 25th, 2008, 8:58 pm

Hello SP,Thanks for your help. It was quite an ordeal looking for the 2 lines of code to solve this problem.Actually, I should have observed that the keypress problem affects all FIGURES containing an active data cursor. The GUI setup is irrelevant.Second, my GUI was not being closed: depending on the operating system, either the GUI was being minimized or focus was switched to the command window. The solution is to turn off some listeners which are activated when the data cursor mode is turned on. When the listeners are on, they forbid the figure's KeyPressFcn to be set.The solution, as pointed out to me:http://groups.google.ca/group/comp.soft ... 442aCheers
Last edited by ana3a on August 24th, 2008, 10:00 pm, edited 1 time in total.