I have a problem with 'togglebutton' in MATLAB 2012a GUI
Mostra commenti meno recenti
Hello everyone;
Let us say we have a text file that contains a number. we need to continuously read the file and print that number on the screen. (Obviously we will need some kind of loop)
Note that reading process should start only when a toggle button is pressed, and stop once the button is pressed again (i.e. released).
My problem is that every time I run the program, it fall in an infinite loop! I assumed that the function will monitor the button state since I include the 'get' function in the loop.
Here is the code: (I have replaced the reading commands with a simple addition statement to simplify the work)
function tbtn1_Callback(hObject,eventData)
%
isPressed = get(hObject,'Value'); % read the button state
if isPressed
set(hObject,'String','Stop');
else
set(hObject,'String','Start');
end
ii = 0;
while isPressed
ii = ii+1 %instead of reading the text file
isPressed = get(hObject,'Value'); % check if the button released
end
end
Hope you can help! Thanks in advanced.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!