How to plot the data array in dynamic?

Each time a data packet is received,you need update the data display,data packet length is about eighty.

8 Commenti

It can done with plot and set..what problem you face?
how long it will take when I use plot and set?
That depends upon how complicated the graphic is and how much additional information you are adding to the display each time.
Thank you!I use “tic and toc”to calculate my data processing time,it takes too long that my data packet will be missed.it is difficlut to realize real-time.
How quickly are you sending data packets? How are you checking for data packets? What graphics are you doing?
0.4ms one packet used UDP and every packet length is about 1458 bytes.I need turn the packet data to double type data and plot it in the figure.the code is like this but it doesn't work:
clear all;
clc;
N=10;%set packet number
len=1458;%packet length
j=0;
data=zeros(N,len);
%received UDP
x=udp('192.168.2.20',166, 'LocalPort', 5030);
x.inputbuffersize=414720;
CH1=zeros(N,len/18);
m=CH1(1,:);
p=plot(m,'MarkerSize',5);
x=-100;
axis([x x+1000 -2.5 2.5]);
grid on;
fopen(x);
for i=1:N
fwrite(x,'get');
data(i,:)=fread(x);
t=1;
for j=1:2:len
y(i,t)=(256*data(i,j+1)+data(i,j))*10/32768;
if(y(i,t)>=10)
y(i,t)=-(20-y(i,t));
end
t=t+1;
end
CH1=y(:,2:9:length(y));
m=[m,CH1(i,:)];
set(p,'YData',m)
drawnow
x=x+81;
axis([x x+1000 -2.5 2.5]);
end
fclose(x);
You need to preallocate y. You are adding more memory to y every iteration of "i".
Note that at 0.4ms per packet, that you would be trying to process 2500 packets per second. For each packet you process, you try to do a graphics update. Unless your graphics display can handle 2500 frames per second, your graphics system is not going to be able to keep up.
If you want real-time graphics updates, you should gather together data corresponding to (say) 50 frames per second (so about 500 packets) and only update the graphics object once per group. That is about 500*81 which is over 40000 points per frame, and even if you have a super wide monitor you will never be able to display that many points per frame. So you need to decide how you want to update your display when the number of data points you receive per second is considerably more than the number of data points you can display per second.

Accedi per commentare.

Risposte (0)

Categorie

Richiesto:

il 11 Giu 2018

Commentato:

il 12 Giu 2018

Community Treasure Hunt

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

Start Hunting!

Translated by