Read live-streaming data into MATLAB from a folder on PC
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Ashutosh
el 22 de Ag. de 2023
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
0 comentarios
Ver también
Categorías
Más información sobre Manage Products en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!