I have a uitable and a function that returns the id of the item once the user clicks on its respective row. The id is also a global variable, as it is used over various functions. The idea is that I create an array with all the user chosen items from the uitable, terminated when save playlist is clicked. Ex. if the user chooses items with id's 5, 7, 9 in succession and then clicks the 'save playlist' button, I want the array to hold
5 7 9
I thought that the best way to do this is using a while loop. The while loop should check if the save button has been clicked. I have a global variable that changes once the program goes into the 'save playlist' button callback function.
The problem is that once the user chooses an ID, the array keeps on iterating until the user chooses another ID, and will keep on iterating etc etc until the save button is clicked. Ex: the user clicks on ID 5, the array will record 55555555555555... recurring until user clicks on ex. ID 7: 555555555555557777777777, since the program keeps on looping and looping without pausing.
The code looks like this:
while (keeprunning)
idvec = [idvec id];
end
keeprunning is a global variable and is initialized with a value of 1 in the opening function. It is changed to 0 in the 'save playlist' callback function.
I thought to fix this problem by introducing a new global variable call it 'itemselected' that initializes in the opening function as 1 and changes to 1 again everytime the cell selection callback is called. After an ID is added to the array in the while loop, this variable resets to 0.
The idea is that the loop should iterate while the 'save playlist' button is not clicked (controlled by the keeprunning global variable) BUT the program should not let the while loop iterate until the user clicks on another row i.e. until the cell selection call back function is called again.
I need something like this but this doesn't work (infinite loop). Or else some other suggestion??
while (keeprunning || trackselected)
idvec = [idvec id];
trackselected = 0;
end
Thank you in advance
I fixed this problem after stopping from thinking about it and doing something else; fascinatingly it came to me as a very simple method.
What I did was create a global array in the CellSelectionCallback. The program checks whether the program was initiated to create a playlist through the use of a boolean variable in the 'create a playlist' button callback, and in this case the global array is appended with the chosen row's item's id. Since the array is global it can be used over different functions. The array is flushed after 'save playlist' button is clicked.
It was as simple as that, however, sometimes simple is not that simple, especially after about 10 hours of seeing matlab code.