Plotting the data continuously coming from serial port
Mostra commenti meno recenti
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.
Risposte (1)
The Matlab Spot
il 20 Dic 2013
0 voti
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 Commento
Gova ReDDy
il 20 Dic 2013
Modificato: Gova ReDDy
il 20 Dic 2013
Categorie
Scopri di più su Instrument Control Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!