Matlab Plot运行速度很慢

时间:2015-08-10 08:36:09

标签: matlab graphics plot

我最近购买了一台配备Intel i7核心,GEFORCE GTX Nvidia 4GB显卡和16GB RAM的游戏电脑。我需要绘制一个包含大量点(大约50,000)的图表,并且某些特定点标记有不同的颜色。

我甚至无法放大或移动图表,因为它的运行速度非常慢。有没有办法加快速度?这应该不是我的电脑的问题,特别是这个简单的图表...

这是代码:

plot(1:length(real_slope),real_slope,'y-*',1:length(real_slope),Y,'r-*')
hold on;
candle(trade_high2(26:end),trade_low2(26:end),trade_close2(26:end),trade_open2(26:end));

for i=2:length(OUT2)

    if Y(i) > Y(i-1) + threshold
        if OUT2(i) < OUT2(i-1)
            error_sum = error_sum + 1;

        end
        hold on;
        plot(i,Y(i),'x','LineWidth',5);
    end

    if Y(i) < Y(i-1) - threshold
        if OUT2(i) > OUT2(i-1)
            error_sum = error_sum + 1;
        end
        hold on;
        plot(i,Y(i),'x','LineWidth',5);
    end    


end

有没有办法加快这个过程?我基本上只想绘制一个烛台图表,同时用一个点(或“x”)标记一些特定的时间点。我基本上将这些特定点绘制为“plot(i,Y(i),'x','LineWidth',5);”在for循环中。有没有更有效的方法来标记这些点?

1 个答案:

答案 0 :(得分:1)

您可以真正受益于diff功能的使用。

使用它,如果我正确理解你的代码,这应该对图形引擎更快更容易。用以下内容替换FOR循环:

Yd = [0 diff(Y)] ;                  %// return a vector of the increment between each point
idxPos = find( Yd >  threshold ) ;  %// get all indices of increment >  threshold
idxNeg = find( Yd < -threshold ) ;  %// get all indices of increment < -threshold

%// now just plot 2 sets of points
hold on
plot( idxPos , Y(idxPos) ,'x','MarkerWidth',5,'LineStyle','none' , 'DisplayName','Positive range');
plot( idxNeg , Y(idxNeg) ,'x','MarkerWidth',5,'LineStyle','none' , 'DisplayName','Negative range');
hold off

%// Use the same "diff" trick for "OUT2"
diffOUT = [0 diff(OUT2)] ;
error_sum = sum( diffOUT(idxPos)<0 ) + sum( diffOUT(idxNeg)>0 ) ;

请注意,我没有在点之间显示一条线,因此您甚至可以在一个单个图形图中绘制该线,如果这就是您所需要的。我将它们分成两组,以防你想以不同的方式显示它们。