Borrar filtros
Borrar filtros

App Designer - Adding two variables halts process

1 visualización (últimos 30 días)
Byron Piper
Byron Piper el 10 de Abr. de 2022
Respondida: Abhishek Chakram el 28 de Sept. de 2023
I have a timer which ticks every 0.5s. It calls a function which adds two numbers, the sum of which is assigned to one of those numbers.
E.g.
x = x + y;
For some reason however, nothing will run after this line. Nothing. It just stops. I get rid of this and everything below works fine. What is going on?
I have a function that is supposed to be called after this line which never gets called if I have this addition above it. I remove the addition, the function then calls. I need the addition but having it just breaks it.
  1 comentario
Geoff Hayes
Geoff Hayes el 11 de Abr. de 2022
@Byron Piper - can you show us the callback function and the code that is called? Are you sure there are no errors in the console window? Are x and y just floating-point variables or are they some other data type?

Iniciar sesión para comentar.

Respuestas (1)

Abhishek Chakram
Abhishek Chakram el 28 de Sept. de 2023
Hi Byron Piper,
It is my understanding that you are facing difficulty setting up a timer and it’s callback in the App Designer. Here is a sample code for the same:
% Initialize variables
x = 5; % Initial value of x
y = 3; % Initial value of y
% Create and start the timer
t = timer('ExecutionMode', 'fixedRate', 'Period', 0.5, 'TimerFcn', @timerCallback);
start(t);
% Timer callback function
function timerCallback(~, ~)
% Add y to x and assign the sum back to x
x = x + y;
% Call a function after the addition
myFunction(x);
end
% Function called after the addition
function myFunction(value)
disp(['The value after addition is: ' num2str(value)]);
end
in this example a timer is created which executes a callback ‘timerCallback‘ that updates the value of x. You can add this [AJ1] to code to any buttonPushedCallback or startupFcn callback.
Best Regards,
Abhishek Chakram

Categorías

Más información sobre Software Development Tools en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by