read a mat file once it appears in the folder?

2 ビュー (過去 30 日間)
Sandy
Sandy 2015 年 2 月 4 日
コメント済み: Niels 2015 年 2 月 5 日
Is it possible that Matlab loads a file once it appears in the folder?
Say a person is sending me many mat files through dropbox. I want to handle each one immediately after it appears in the folder. I don't want to handle them after all files are there because it may take a very long waiting time.
Is there a way Matlab can recognize a new appeared file? Or any other thoughts can solve this problem?
Thank you very much.

採用された回答

Niels
Niels 2015 年 2 月 4 日
One approach you could use is to write the filenames of all the current .mat files to e.g. a text document. You can import the contents of this text document, compare them with the actual folder contents, load the new files and then add those to the text document as well.
  2 件のコメント
Sandy
Sandy 2015 年 2 月 4 日
That sounds brilliant. Just have an additional concern, if there is no new file at one time point, how can I tell matlab to wait and automatically load a new one when it appears. Do I have to set up a time interval and compare the document every few seconds?
Thank you again.
Niels
Niels 2015 年 2 月 5 日
You could make a simple while-loop with no way to break out. Add a pause(...) at the end of every iteration and let it recheck afterwards.
It would look like this:
while(statement_that_will_always_be_true)
load text file
compare contents with .mat files in directory
if different
append text file with new .mat
do something with .mat file
end
close text file
pause 30 seconds
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFiles and Folders についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by