Data Streaming from updating .txt file
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi, I have a software that collect data from a hardware, these data are stored in text files and keep updeating, now I am doing some experiment and I want to use the real time data in those .txt files and import it into matlab, I want to be able to import the data every specific time lets say 1 minute, and then after impleminting some processes on the data I want to import more data from the point it stopped lastly. Is there a documintation specificlly for this purpose? could u please refere me to?
댓글 수: 0
답변 (1개)
Amith
2024년 8월 23일
Hi Omilnoth,
I understand that you would like to import data from a text file. You can achieve this using the importdata function. For more details, you can refer to this MATLAB documentation: https://www.mathworks.com/help/matlab/ref/importdata.html#btk7vi1-2_1
To import data from a text file, perform a specific operation, and repeat this process, you can refer to the following code:
filename = 'yourfile.txt'; % Replace with your actual file name
while true
% Import data from the text file
data = importdata(filename);
% Open the file in write mode, which clears its contents
fid = fopen(filename, 'w');
% Close the file
fclose(fid);
% Display the imported data (optional) - here you can perform the operations you would
% like to do
disp(data);
% Pause for 10 seconds
pause(10);
end
This script will continuously import data from `yourfile.txt` every 10 seconds. It deletes the file's contents after reading and displays the previously read contents in the MATLAB command window. You can replace `disp(data)` with any processing or analysis you wish to perform on the imported data. By clearing the file's contents up to that point, new data can be populated and subsequently processed for further operations.
I hope this would help you achieve the desired result.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!