most efficient way of plotting surf/mesh from live data

9 visualizzazioni (ultimi 30 giorni)
For demo purposes, I've made a little class that streams live data from some other software I programmed via TCP and I'd like to plot the incoming data as a 3D mesh or surface. The code looks something like this:
c = MyClient( 'localhost', 5555 );
c.connect();
ButtonHandle = uicontrol('Style', 'PushButton', ...
'String', 'Stop loop', ...
'Callback', 'delete(gcbf)');
while true
if ~ishandle(ButtonHandle)
fprintf( 'Loop stopped by user\n' );
break;
end
[ret,m] = c.read();
if( ret == true )
surf( m );
zlim([0 1]);
%colorbar;
else
pause( .05 );
end
end
I would like the value range to be constant, so I inserted zlim. This works fine, basically. Now when I add a colorbar, everything seems to become really slow. I'm not sure how the plotting works internally, but I thought maybe it's not meant to be used this way. My hypothesis is that the plot is created from scratch each loop. If that's true, is there a way of reusing the mesh and just update the values? If not, how would I do something like that in MATLAB?
I guess my overall question is what is a recommended way of plotting live data? I also noticed that when 3D rotating the plot, it jumps back to initial perspective all the time, so ideally I would like to have a mesh I can just update with new values. Is that even possible?

Risposta accettata

jonas
jonas il 17 Ago 2020
Modificato: jonas il 17 Ago 2020
It is correct that creating a new surface object every time is slowing you down. Updating the existing object is much faster. Compare these two
[X,Y] = meshgrid(1:100,1:100);
Z = rand(size(X));
tic
surf(X,Y,Z)
for i = 1:10
surf(X,Y,Z);
end
t1 = toc;
tic
h = surf(X,Y,Z);
for i = 1:10
Z = rand(size(X));
h.ZData = Z;
end
t2 = toc;
t1/t2
ans =
5.9726

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by