help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Testing demo code


From: RT
Subject: Testing demo code
Date: Tue, 13 Aug 2019 00:02:54 -0400

I was testing some code from https://stackoverflow.com/questions/29948697/switching-values-to-plot-using-keyboard-input

I type in "change_dataset_demo" the plot is created but the left and mouse keys along with the mouse doesn't seem to be working when it comes to switching between data sets.

What comes back is :
ans =

  scalar structure containing the fields:

    fig =                    1
    plot =    -111.057442267399

Code below:
function h = change_dataset_demo

%// sample data
nDataset = 8 ;
x = linspace(0,2*pi,50).' ;     %'// ignore this comment
data = "" x*(1:nDataset) ) ;

index.max = nDataset ;
index.current = 1 ;

%// Plot the first one
h.fig = figure ;
h.plot = plot( data(:,index.current) ) ;

%// store data in figure appdata
setappdata( h.fig , 'data',  data )
setappdata( h.fig , 'index', index )

%// set the figure event callbacks
set(h.fig, 'KeyPressFcn', @KeyPressFcn_callback ) ;     %// Set figure KeyPressFcn function
set(h.fig, 'WindowScrollWheelFcn',@mouseWheelCallback)  %// Set figure Mouse wheel function

guidata( h.fig , h )


function mouseWheelCallback(hobj,evt)
    update_display( hobj , evt.VerticalScrollCount )


function KeyPressFcn_callback(hobj,evt)
    if ~isempty( evt.Modifier ) ; return ; end  % Bail out if there is a modifier

    switch evt.Key
        case 'rightarrow'
            increment = +1 ;
        case 'leftarrow'
            increment = -1 ;
        otherwise
            % do nothing
            return ;
    end
    update_display( hobj , increment )


function update_display( hobj , increment )

    h = guidata( hobj ) ;
    index = getappdata( h.fig , 'index' ) ;
    data  = getappdata( h.fig , 'data' ) ;

    newindex = index.current + increment ;
    %// roll over if we go out of bound
    if newindex > index.max
        newindex = 1 ;
    elseif newindex < 1
        newindex = index.max ;
    end
    set( h.plot , 'YData' , data(:,newindex) ) ;
    index.current = newindex ;
    setappdata( h.fig , 'index', index )

--


reply via email to

[Prev in Thread] Current Thread [Next in Thread]