필터 지우기
필터 지우기

Plotting the data continuously coming from serial port

조회 수: 1 (최근 30일)
Gova ReDDy
Gova ReDDy 2013년 12월 19일
편집: Gova ReDDy 2013년 12월 20일
Hello,
I am continuously getting data to matlab through the serial communication and using the below code Iam plotting the only the collected 5000 samples that were saved in the file 'sample_5000.txt'.
delete(instrfindall)
sp = open_com_port(8);
file_name = 'sample_5000.txt';
if exist(file_name)
delete(file_name);
end
fid = fopen(file_name,'w');
for m=1:5000
nb = sp.BytesAvailable;
%nb = floor(nb/2)*2;
if(nb)
%buf = fread(sp, nb, 'uchar');
[tline,count] = fgetl(sp);
data = str2num(char(tline));
data=(data*2.5)/4095;
fprintf(fid,'%f \n',data);
end
end
fclose(sp);
delete(sp);
fclose(fid);
Here the open_com_port is a function for cerial port settings. But can one explain how to modify the code so that it will plot the data continuously in a figure showing last 2500 samples in the figure and it sould be updated after acquiring every 500 samples form the serial communication. Thnaks.

답변 (1개)

The Matlab Spot
The Matlab Spot 2013년 12월 20일
Take reference from this file-exchange submit. In this the plot updates itself and axes scrolls automatically as specified in your requirement. It is based on update line handle data of the plotted signal lines of the figure
  댓글 수: 1
Gova ReDDy
Gova ReDDy 2013년 12월 20일
편집: Gova ReDDy 2013년 12월 20일
I still don't understand how to plot the serially comming data. I mean the data of 500 samples (each collected in 2ms at the controller side)will be sent after 1 sec in 2ms interval to the serial port into matlab.So, the 500samples will be collected in 1 sec at controller side and after 1sec the 500samples will be sent in 2msec.Then the next 500samples collected at mocrocontroller and in the next 2ms interval after this 1sec interval of data collection the 500 samples will be again sent to the matalab through serial port.
I want to plot this obtained data continuously and it should show 2500 samples(5sec data plot) in a figure plot and after that it should update for the next 500 samples.
Can I know how to do this.

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by