How do I make the time control program run?

1 次查看(过去 30 天)
Now, there are two parts of the program, represented by code1 and code2. In 1000 seconds, code1 runs every 10 seconds. After code1 runs, code2 uses the result of code1, and then runs it every 1 second.The running of the program is controlled by time. How can I implement this function?
----------------------------------------------------------------------------------------------------
Sorry!After reading the literature carefully, I found that my question may be wrong. In fact, my purpose is to simulate the localization algorithm in the paper. The following is the revised question:
The function of code1 is to calculate the coordinates (estimated values) of underwater sensor nodes, and the function of code2 is to describe the changes of real coordinates with water flow.
The sensor node needs to run code1 every time T, where T is the positioning period. In addition, I need to calculate the real coordinates of the node at each positioning moment. After code1 runs, an estimated coordinates vector will be obtained. After code2 runs, a real coordinates vector will be obtained. Then I want to calculate the positioning error.
Fortunately, the speed of real coordinates changes regularly. When the values of time t are 0~999 and 1000~1999, the speed changes of the real coordinates are similar. I think this is because the formula contains a sine function and a cosine function. So code2 can be independent of code1. Am I right?
where Vx is the speed in the x axis and Vy is the speed in the y axis. Also, k1, k2, k3, λ and v are variables which are closely related to environment factors. These variables all follow a normal distribution, but the mean and standard deviation are different. x, y are current position coordinates of sensor node.
If my above understanding is wrong, how can I execute code1 and code2?
(Please understand. There may be some errors in my English expression.)

采纳的回答

Deepak Meena
Deepak Meena 2021-3-15
Hi Li
For making Time controlled Program run , I suggest you to have a look at tic toc. But My understanding is that , your code performance will vary with the machine and the platform.
Also you aim to run the code2 every 1 second , so what if the exectution time of code2 takes more than 1 second ?
Please let us know if you need further assistance.
  1 个评论
Li Qing
Li Qing 2021-3-15
Hi Deepak
Sorry!After reading the literature carefully, I found that my question may be wrong. In fact, my purpose is to simulate the localization algorithm in the paper. The following is the revised question:
The function of code1 is to calculate the coordinates (estimated values) of underwater sensor nodes, and the function of code2 is to describe the changes of real coordinates with water flow.
The sensor node needs to run code1 every time T, where T is the positioning period. In addition, I need to calculate the real coordinates of the node at each positioning moment. After code1 runs, an estimated coordinates vector will be obtained. After code2 runs, a real coordinates vector will be obtained. Then I want to calculate the positioning error.
Fortunately, the speed of real coordinates changes regularly. When the values of time t are 0~999 and 1000~1999, the speed changes of the real coordinates are similar. I think this is because the formula contains a sine function and a cosine function. So code2 can be independent of code1. Am I right?
where Vx is the speed in the x axis and Vy is the speed in the y axis. Also, k1, k2, k3, λ and v are variables which are closely related to environment factors. These variables all follow a normal distribution, but the mean and standard deviation are different. x, y are current position coordinates of sensor node.
If my above understanding is wrong, how can I execute code1 and code2?
(Please understand. There may be some errors in my English expression.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Robust Control Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by