If x>5 for y seconds, then z

1 回表示 (過去 30 日間)
mehmet aydogan
mehmet aydogan 2022 年 11 月 22 日
コメント済み: mehmet aydogan 2022 年 11 月 23 日
How can I write this in Matlab? Thanks.
If x>5 for y seconds, then z
  2 件のコメント
Image Analyst
Image Analyst 2022 年 11 月 22 日
You can invest 2 hours here and learn the basics:
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
mehmet aydogan
mehmet aydogan 2022 年 11 月 22 日
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

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2022 年 11 月 22 日
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 件のコメント
mehmet aydogan
mehmet aydogan 2022 年 11 月 22 日
I am planning to use the function in stateflow. I read somewhere (please don't ask me where, can't find it now) that tic-toc is not recommended with stateflow. So, that's why I thought maybe there is a more elegant way. But honestly, I didn't try it myself. Maybe it will work flawlessly.
I found timer function but it looks a bit too complicated.
Of course stateflow has its temporal logical operators as well. But I couldn't put my stateflow chart together in the way I want it. (And sorry, can't paste the whole project here obvisously. And yes, maybe I should re-consider my chart architecture.) This is my very first stateflow project, and the first matlab project after a looong time. I guess the best way is to try and see different methods.
Anyway, thanks for your time.
mehmet aydogan
mehmet aydogan 2022 年 11 月 23 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNaming Conventions についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by