Read live-streaming data into MATLAB from a folder on PC

조회 수: 6 (최근 30일)
Daniel Du Toit
Daniel Du Toit 2023년 8월 6일
답변: Ashutosh 2023년 8월 22일
Hi
I am doing experimental testing on a vehicle where accelerometers is mounted to the floor of the vehicle and measures data. The measurement files will be sent to a server at a facility while the vehicle is in motion and stored in a file directory. The data is sent every 5 minutes containing the 5 minutes worth of data. The files will be stored according to YYYY/MM/DD HH:MM:SS in the same file directory.
I am looking for help to write a matlab script to detect when a new file is presented in the folder where the files are stored and then read it into matlab to be analysed further.

답변 (1개)

Ashutosh
Ashutosh 2023년 8월 22일
To detect when a new file is added to a specific folder and read it into MATLAB for further analysis This approach is to be followed as to get the path of the folder where files are present and get list of all desired files in an infinite loop and check if there are any new files present or not and then pause for 5 minutes to wait to get the new data and meanwhile work on the analysis which must be done on the data imported.
Below is the pseudo code which shows the above explained approach:
% Specify the file directory
fileDir = 'folder_path';
% Infinite loop to continuously check for new files
while true
% Get the list of files in the directory
files = dir(fullfile(fileDir, '*.txt')); % Modify the file extension if needed
% Check if there are any new files
if numel(files) > 0
% Get the latest file
latestFile = files(end).name;
% Read the data from the file using importdata
filePath = fullfile(fileDir, latestFile);
data = importdata(filePath);
% Perform further analysis on the data
% …....
end
% Pause for a specific duration before checking for new files again
pause(300); % 300 seconds = 5 minutes
end

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by