Is there a faster alternative to plot in MATLAB?

3 views (last 30 days)
I have a large figure with multiple subplots being updated contenously with live data. The problem is that there is a delay because I have almost 10 subplot functions called at the same time. To my understanding MATLAB changed its graphic engine a few years back and that's what caused plotting to slow down. So I'm wondering if there is an alternative to plot or if there is a more efficent way of doing my plotting.
Here is an example of my code:
subplot('Position',[width+3*margin_x,1-height-margin_y,width,height])
plot(X,Y1)
subplot('Position',[width+3*margin_x,0.75-height-margin_y,width,height])
plot(X,Y2)
subplot('Position',[width+3*margin_x,0.5-height-margin_y,width,height])
plot(X,Y3)
subplot('Position',[width+3*margin_x,0.25-height-margin_y,width,height])
plot(X,Y4)
drawnow
This post seemed to suggest using set in place of plot, but I don't understand why that would be any faster.

Answers (1)

Kevin Phung
Kevin Phung on 24 Jan 2019
Edited: Kevin Phung on 24 Jan 2019
im not too sure how the rest of your code looks like, but maybe you can clean it up by just assigning handles to your axes (each subplot).
so something like:
%% initialize axes
s1= subplot('Position',[width+3*margin_x,1-height-margin_y,width,height])
s2=subplot('Position',[width+3*margin_x,0.75-height-margin_y,width,height])
s3=subplot('Position',[width+3*margin_x,0.5-height-margin_y,width,height])
s4= subplot('Position',[width+3*margin_x,0.25-height-margin_y,width,height])
%% this part of your code does the updating, points to the specific subplot
plot(s1,X,Y1)
plot(s2,X,Y2)
plot(s3,X,Y3)
plot(s4,X,Y4)
drawnow
%% alternative method, instead of destroying and
% creating a new line object each iteration which takes more time,
% just change their values
s1.Children.YData = Y1;
s2.Children.YData = Y2;
s3.Children.YData = Y3;
s4.Children.YData = Y4;
% This method assumes there is only 1 line object (Children) for each axis.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!