Terminating while loop with a pushbutton Matlab -


i have uitable , function returns id of item once user clicks on respective row. id global variable, used on various functions. idea create array user chosen items uitable, terminated when save playlist clicked. ex. if user chooses items id's 5, 7, 9 in succession , clicks 'save playlist' button, want array hold

5 7 9 

i thought best way using while loop. while loop should check if save button has been clicked. have global variable changes once program goes 'save playlist' button callback function.

the problem once user chooses id, array keeps on iterating until user chooses id, , keep on iterating etc etc until save button clicked. ex: user clicks on id 5, array record 55555555555555... recurring until user clicks on ex. id 7: 555555555555557777777777, since program keeps on looping , looping without pausing.

the code looks this:

 while (keeprunning)      idvec = [idvec id];  end 

keeprunning global variable , initialized value of 1 in opening function. changed 0 in 'save playlist' callback function.

i thought fix problem introducing new global variable call 'itemselected' initializes in opening function 1 , changes 1 again everytime cell selection callback called. after id added array in while loop, variable resets 0.

the idea loop should iterate while 'save playlist' button not clicked (controlled keeprunning global variable) program should not let while loop iterate until user clicks on row i.e. until cell selection call function called again.

i need doesn't work (infinite loop). or else other suggestion??

 while (keeprunning || trackselected)     idvec = [idvec id];     trackselected = 0;  end 

thank in advance

to record history of user selecting fields inside uitable, this:

function tbl_example    % create figure   fh = figure('visible', 'off')    ud.selected_list  = [];     d = gallery('integerdata',100,[10 3],0);   t = uitable(fh,'data',d,'columnwidth',{50}, 'cellselectioncallback',    @cell_history );    set( fh, 'visible', 'on' );   set( fh, 'userdata', ud ); return  function cell_history( h, event_data )    fh = get( h, 'parent' )   ud = get( fh, 'userdata' );    indx = event_data.indices;    ud.selected_list = [ ud.selected_list h.data( indx(1), indx(2) ) ]     set( fh, 'userdata', ud ); return 

then, when hit "playlist" button, read userdata field in parent figure handle.


Popular posts from this blog