Matlab GUIDE - Change color while loop is running?
Mostrar comentarios más antiguos
Hi,
I'm trying to simulate a low battery scenario in matlab using GUIDE. I was wondering how to get the GUIDE to pop up with a green box (representing an LED), run a loop, then the "LED" turns red once the loop gets to a certain point.
I'm able to do this once I press a pushbutton, but how can I simulate this without pressing the button? Here's what I have:
if true
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
battery=50
for time=1:100
while battery>0
battery=battery-2
if battery<20 && battery>0
set(hObject,'BackgroundColor','red')
set(handles.Screen,'String','Low Battery. Plug in Charger')
else
end
pause(0.1)
end
end
end
Any ideas on how I can do this?
Thanks for your time.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 27 de Mzo. de 2014
0 votos
Well, how would you like to start the simulation running?
2 comentarios
thebasher
el 27 de Mzo. de 2014
Image Analyst
el 27 de Mzo. de 2014
You can put the code in the OpeningFcn to start it running as soon as the GUI is launched. You don't need a timer, unless you want to. You could do it like you had it, with pause(). Though a timer frees up your GUI to do other things if you want other things to happen while your simulation is draining the battery.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!