您是否尝试过将渲染方法更改为的简单解决方案OpenGL
?
opengl hardware;
set(gcf,'Renderer','OpenGL');
警告!
在这种模式下会有一些东西消失,看起来会有点不同,但通常剧情会运行much更快,特别是如果您有硬件加速器。
顺便问一下,您确定您真的会获得性能提升吗?
例如,根据我的经验,WPF
图形在C#
比 Matlab 慢得多,尤其是散点图和圆圈。
Edit:我想到了这样一个事实:实际绘制到屏幕上的点数不可能那么多。基本上,这意味着您需要在屏幕上有像素的地方进行插值。查看这个对象:
classdef InterpolatedPlot < handle
properties(Access=private)
hPlot;
end
methods(Access=public)
function this = InterpolatedPlot(x,y,varargin)
this.hPlot = plot(0,0,varargin{:});
this.setXY(x,y);
end
end
methods
function setXY(this,x,y)
parent = get(this.hPlot,'Parent');
set(parent,'Units','Pixels')
sz = get(parent,'Position');
width = sz(3); %Actual width in pixels
subSampleX = linspace(min(x(:)),max(x(:)),width);
subSampleY = interp1(x,y,subSampleX);
set(this.hPlot,'XData',subSampleX,'YData',subSampleY);
end
end
end
这是如何使用它的示例:
function TestALotOfPoints()
x = rand(10000,1);
y = rand(10000,1);
ip = InterpolatedPlot(x,y,'color','r','LineWidth',2);
end
另一个可能的改进:另外,如果您的 x 数据已排序,您可以使用interp1q
代替interp
,这会快得多。
classdef InterpolatedPlot < handle
properties(Access=private)
hPlot;
end
% properties(Access=public)
% XData;
% YData;
% end
methods(Access=public)
function this = InterpolatedPlot(x,y,varargin)
this.hPlot = plot(0,0,varargin{:});
this.setXY(x,y);
% this.XData = x;
% this.YData = y;
end
end
methods
function setXY(this,x,y)
parent = get(this.hPlot,'Parent');
set(parent,'Units','Pixels')
sz = get(parent,'Position');
width = sz(3); %Actual width in pixels
subSampleX = linspace(min(x(:)),max(x(:)),width);
subSampleY = interp1q(x,y,transpose(subSampleX));
set(this.hPlot,'XData',subSampleX,'YData',subSampleY);
end
end
end
以及用例:
function TestALotOfPoints()
x = rand(10000,1);
y = rand(10000,1);
x = sort(x);
ip = InterpolatedPlot(x,y,'color','r','LineWidth',2);
end