Filter löschen
Filter löschen

App Designer - Adding two variables halts process

1 Ansicht (letzte 30 Tage)
Byron Piper
Byron Piper am 10 Apr. 2022
Beantwortet: Abhishek Chakram am 28 Sep. 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 Kommentar
Geoff Hayes
Geoff Hayes am 11 Apr. 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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Abhishek Chakram
Abhishek Chakram am 28 Sep. 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

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by