Real time plotting of data from csv file
9 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am stuck in one small problem. I am reading data from some sensor and capturing into csv file using terminal. How can I plot that data in real time by continuously reading file. Any lead will be helpful.
Thanks!
0 个评论
回答(1 个)
Deepak
2024-10-17
Hi Kishor,
From my understanding, you are reading the data from a sensor and capturing it into a CSV file. You want to plot the data continuously from the CSV file in real time.
To achieve this, we can first set up the MATLAB environment by defining the CSV file path and figure. Now, we can iterate over a loop to continuously read the data from the CSV file using “readmatrix” function and plot it using the “plot” function in MATLAB. As the size of CSV file continues to increase over time, updated plots will get generated in real time.
Here is the MATLAB code to accomplish this task:
% Define the file path
filePath = 'your_sensor_data.csv';
figure;
while true
% Read the CSV file
data = readmatrix(filePath);
% Assuming the data has two columns, time and sensor value
time = data(:, 1);
sensorValue = data(:, 2);
plot(time, sensorValue);
xlabel('Time');
ylabel('Sensor Value');
title('Real-Time Sensor Data');
grid on;
% Pause for a short time to allow the plot to update
pause(1);
% Clear the plot for the next update
clf;
end
Please find attached the documentation of functions used for reference:
I hope you found the information insightful.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!