If x>5 for y seconds, then z

1 view (last 30 days)
mehmet aydogan
mehmet aydogan on 22 Nov 2022
Commented: mehmet aydogan on 23 Nov 2022
How can I write this in Matlab? Thanks.
If x>5 for y seconds, then z
  2 Comments
mehmet aydogan
mehmet aydogan on 22 Nov 2022
Something like this? Anything suggestion that doesn't use tic-toc?
x=6;
if x>5
tic;
pause(5)
if toc>4
y=2
end
end

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Nov 2022
What's wrong with tic and toc?
startTime = tic;
elapsedTime = toc(startTime);
loopCounter = 1;
while elaspedTime < 5
fprintf('Iteration %d.\n', loopCounter)
pause(0.4); % Waste some time.
elapsedTime = toc(startTime);
end
  2 Comments
mehmet aydogan
mehmet aydogan on 23 Nov 2022
I have just tried tic-toc method. The problem is that tic-toc calculates the delay in real time. If I add a breakpoint to debug, then the elapsed time become very long. Need a solution with simulation time.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!