Using variable in a loop outside the loop
3 ビュー (過去 30 日間)
古いコメントを表示
I am getting real time data every 5seconds (with pause) with a loop and the data goes into matrix. How can I use the current data outside the loop and proceed to do computation with the most current data (the first row in the matrix)? When the loop is running I can not do anything until it is finished.. And I need to create infinite loop to continuously get the data.
1 件のコメント
Dhenish
2023 年 12 月 8 日
I have also this type of requirement so can you give me guidelines for this.
I also want variables value after every itration. i just want to change the value of varibales which is changing dynamiclly in every 5 seconds and need to store that variables in the base workspace.
Thanks in advance!!
採用された回答
Jan
2015 年 5 月 15 日
Matlab is single threaded. Creating an infinite loop to acquire data means that there is no "outside the loop". So better use a timer to read the data and let the main loop process the current values.
2 件のコメント
Walter Roberson
2015 年 5 月 16 日
The parallel computing toolbox would not be very effective for this, not in general. However you could create different labs, and in the lab that you were doing the reading of data, you could labSend() the new value to the other routine.
As the data will be received asynchronously, you would want to have that other code use labProbe to determine whether it has been sent anything, and if so to labReceive() it. Be sure to loop on that just in case multiple values have been received.
その他の回答 (1 件)
Walter Roberson
2015 年 5 月 16 日
Pretty much all of the data reception methods allow you to set a callback when data is ready (though if you are using the session-based interface on the DAQ and are waiting for a Trigger, then you might have to add a listener.) You would configure the data reception to trigger the callback every time the data was ready, and in the callback you would receive the data and store it away in a known location.
Meanwhile in your data processing loop, you would check once per loop to see if new data was received, and you would update your matrices if so.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!