most efficient way of plotting surf/mesh from live data

26 ビュー (過去 30 日間)
Roland Aigner
Roland Aigner 2020 年 8 月 17 日
編集済み: jonas 2020 年 8 月 17 日
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?

採用された回答

jonas
jonas 2020 年 8 月 17 日
編集済み: jonas 2020 年 8 月 17 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by