How to plot a graph from a growing .csv file with time?

조회 수: 4 (최근 30일)
Seiji Kuroda
Seiji Kuroda 2021년 1월 31일
댓글: Seiji Kuroda 2021년 2월 3일
Hi! I want to plot a graph from a .csv file, which is created by an instrument and grows with measurement time. The file consists of two columns, i.e., elapsed time and measured values. My test program worked with writematrix, readmatrix as shown below but as the file gets bigger, it becomes slow as it reads the whole file every time. Is there a way to just read newly added date from the .csv file and add points to the already drawn plot?
%Test program
m=zeros(1,2);
dm=zeros(1,2);
save('TestData.csv','m');
h = animatedline;
for i=1:1E3
x=0.01*i;
y=sin(4*x);
dm(1,1)=x;dm(1,2)=y;
m=cat(1,m,dm);
writematrix(m,'TestData.csv');
q=readmatrix('TestData.csv');
addpoints(h,q(i,1),q(i,2));
drawnow limitrate;
end

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 1월 31일
편집: KALYAN ACHARJYA 2021년 1월 31일
One way:
MATLAB process the codes sequentially, If possible read the data from instrument one by one and plot them accordingly till the while condition true, you can consider the time period during the loop as a while loop condition.
while true
% read the elapsed time and measured values.
plot(elapsed_time,measured_val);
hold on;
end
  댓글 수: 1
Seiji Kuroda
Seiji Kuroda 2021년 2월 3일
Dear Kalyan,
Thank you very much for your answer.
The instrument writes data to a CSV file at a constant rate, say 100 data/sec max.
Therefore, we are trying to find a way to add plot points at a slower rate which MATLAB
can handle, maybe 10 times/sec?
In such case, we need to read 10 new points from the previous cycle.
If you have a good idea, let us know.
Seiji

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by