How to check whether button is pressed
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have an idea to simulate scope output in my gui. My plan was to get block parameters, value and time, and then use drawnow to keep updating the plot. Everything was fine, but I had to use infinite while loop, cause my simulation stops as user clicks certain button. That's the problem - as program goes into that loop it won't execute any other instruction, so it can't chcek whether "Off" button is pressed (at least I think that's the way it works, because that button should stop the simulation as well, but it doesn't...) . Is there any way to realize that idea?
Here's my code:
block = [...]
rto = get_param(block,'RuntimeObject');
i=1;
while 1 == 1
val(i) = rto.OutputPort(1).Data;
time(i) = rto.CurrentTime;
pause(0.01)
drawnow
plot(time,val)
i = i+1;
end
12 comentarios
Voss
el 25 de En. de 2024
"There's no need for drawnow in that solution"
When I run this:
f = figure();
btn = uicontrol('Parent',f,'Style','togglebutton','String','Stop','Value',0);
while true
if get(btn,'Value')
disp('Stop button down: exiting the loop!')
break
end
% drawnow
end
The loop continues running after I click the button until I do ctrl+c.
Respuestas (0)
Ver también
Categorías
Más información sobre Simulink Environment Customization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!