Hi, this is my first spread and hope some feedbacks. I need to do the following tasks simultaneously. How can I use Matlab to achieve it? (1) Download data every second from a remote terminal/server. (2) Process the data to judge if the secondly updated data satisfy certain conditions or not. (3) When certain conditions are met, send commands to the remote terminal/server to operate tasks.

 채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 7일

0 개 추천

You can use timer() objects to run a routine at periodic intervals.
You can download data in multiple ways, including ftp(); urlread(); the fairly new webread(); scp() from the File Exchange, or by using tcp() to request the data.
One difficulty you will need to deal with is that downloading the data may require more than one second. TCP connections retry when data packets are dropped, so TCP based requests can take an indefinite amount of time to return.
All of the ways I listed to download data can also be used to send commands to a server.

댓글 수: 2

Wei Chen
Wei Chen 2015년 9월 7일
Walter, thank you for the answer. The hard part is that when step (2) and step(3) operated, it is very likely to be longer than 1 second. This might result in missing some observations that need to be downloaded in step (1). Can timer() solve this problem? Thanks!
Walter Roberson
Walter Roberson 2015년 9월 9일
timer() is not suitable for the case where the operating to execute takes longer than the period with which it is to execute.
I guess if you had the Parallel Computing Toolbox, you could use SPMD, with one lab running a timer and dispatching a "download and process" instruction to an available lab. You would need at least three workers, one controlling and two overlapping downloads. If your download is bandwidth limited rather than being limited by the amount of time the server "thinks about it" then the second download will slow down the first one, resulting in it being later. That could potentially push the download into requiring more than 2 seconds in which case you would need another worker yet.
If you are needing to poll every 1 second and you need to react to each individual download, then chances are that the instructions you execute should reflect the latest available information. But depending on how you analyze the data, if it takes longer than the poll interval to download the data, it could be that the second download has already downloaded an update that you should be taking into account. But whether you can pull out the new data depends on how the download is being done.

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

추가 답변 (1개)

Guillaume
Guillaume 2015년 9월 7일

0 개 추천

Hum, you're describing a very sequential process (download -> process -> feedback). What exactly are you hoping to parallelise?
In any case, if you want to execute parallel tasks with matlab, you need the parallel toolbox. Without the toolbox it possibly could be achieved by deferring to Java, .Net, or mex but in that case you may as well write your entire code in Java, .Net, or C

댓글 수: 1

Wei Chen
Wei Chen 2015년 9월 7일
Guillaume, thank you for the answer. Let me clarify here. I need to download the data every second, but it is very likely that the time for evaluation and operating commands (step (2) and (3)) might be longer than one second. I need that when Matlab code evaluate and operate commands, the data download code still download data every second. Do you have some suggestions?

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

카테고리

도움말 센터File Exchange에서 Downloads에 대해 자세히 알아보기

질문:

2015년 9월 7일

댓글:

2015년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by