Programación de botones en App Designer

31 Ansichten (letzte 30 Tage)
Cristian Cuenca Moreno
Cristian Cuenca Moreno am 16 Jun. 2022
Beantwortet: Amit Dhakite am 20 Sep. 2023
Hola, tengo un problema a la hora de programar dos botones de App Designer, uno para capturar imágenes desde una webcam en bucle, y otro para detener este proceso.
El botón de capturar las imágenes lo he configurado de la siguiente manera:
function MonitorizarButtonPushed(app, event)
runLoop = 'true';
while runLoop
parking();
app.Plazaslibres3.Value = plazaslibres;
if plazaslibres > 0
app.Lamp_3.Color = [0 1 0]
else
app.Lamp_3.Color = [1 0 0]
end
parking_con_coches = imagenparking;
imagesc(app.imgparking,parking_con_coches);
hold(app.imgparking,"on")
for k = 1:length(porcentajeparking)
x = centroidesparking(k, 1);
y = centroidesparking(k, 2);
plazas = sprintf('%d', k);
if (porcentaje_fijadoparking(k) > 0.50)
%Consideraremos una plaza ocupada cuando más del 50% de la plaza está ocupada
plot(app.imgparking, x, y, 'rx', 'MarkerSize', 30, 'LineWidth', 4);
text(app.imgparking, x-10, y+30, plazas, 'Color', 'r', 'FontSize', 15, 'FontWeight', 'bold');
else
plot(app.imgparking, x, y, 'g.', 'MarkerSize', 40, 'LineWidth', 4);
text(app.imgparking, x-10, y+30, plazas, 'Color', 'g', 'FontSize', 15, 'FontWeight', 'bold');
end
end
end
Pero el botón de parar no consigo que me funcione, ¿alguien sabría como hacerlo?

Antworten (1)

Amit Dhakite
Amit Dhakite am 20 Sep. 2023
Hi,
I understand that you want to program two buttons in App Designer, such that pressing one button will start clicking pictures in a loop and another button will stop this loop.
In order to do so, you can:
  1. Create a Boolean type variable "runLoop" with an initial value "false".
  2. Now, you can modify that variable inside the "MonitorizarButtonPushed()" with value "true". In this function, you can perform operations related to capturing the images.
  3. Inside the second callback function to stop this loop, you can modify the value of "runLoop" again to "false".
Please go through the below code to understand how you can add another variable and modify it in both the callbacks:
% Creating a variable which will work as a flag for capturing the images
% You can do this by clicking on Add Property option in "INSERT" section in
% the toolbar.
properties (Access = public)
runLoop = false;
end
% Callback function responsible for capturing the images in a loop
function MonitorizarButtonPushed(app, event)
% You can access the public variables using app.variableName
app.runLoop = true;
while runLoop
% Here, you can perform the operations to capture the images
end
end
% Callback function responsible for stopping the loop
function StopCapturingButtonPushed(app, event)
app.runLoop = false;
% This will make your loop stop
end
I hope the above modifications will help you to resolve your issue.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!