필터 지우기
필터 지우기

App Designer - Adding two variables halts process

조회 수: 1 (최근 30일)
Byron Piper
Byron Piper 2022년 4월 10일
답변: Abhishek Chakram 2023년 9월 28일
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
Geoff Hayes
Geoff Hayes 2022년 4월 11일
@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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhishek Chakram
Abhishek Chakram 2023년 9월 28일
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

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by