2016-11-02 39 views
0

我已经写了一个简单的八度绘图功能,下面的代码,但不幸的是需要一些时间来绘图。有什么方法可以加快速度?加快环形八度绘图功能

function hilo_conditional_plot(high , low , condition) 
%HILO_CONDITIONAL_PLOT 
% Takes high, low and condition input vectors and plots a line chart of highs 
% and lows coloured according to the condtion. For this basic version there 
% are only 3 conditons; 1 for long, -1 for short and 0 for neutral; with the 
% respective plot colours being blue, red and green. 

date = (1 : length(high))' ; 
hold on ; 

for ii = 1 : length(high) 

    if condition(ii) == 1 
    line([ date(ii) date(ii) ] , [ low(ii) high(ii) ] , 'Color' , 'b' , 'linewidth' , 2) ; 
    elseif condition(ii) == -1 
    line([ date(ii) date(ii) ] , [ low(ii) high(ii) ] , 'Color' , 'r' , 'linewidth' , 2) ; 
    elseif condition == 0 
    line([ date(ii) date(ii) ] , [ low(ii) high(ii) ] , 'Color' , 'g' , 'linewidth' , 2) ; 
    else 
    printf('Error in condition vector - a value != 1,-1 or 0') ; 
    end 

end 

grid minor on ; 

hold off ; 

编辑:高和低列将包含数值财务数据和条件列将包含一个1,-1或0的值,E,G。

1.2 1.1 0 
1.3 1.1 1 
1.4 0.9 -1 
+0

跨张贴在http://octave.1599824.n4.nabble.com/Speeding-up-a-plotting-function -td4680459.html – babelproofreader

+1

您能否提供一个'high','low'和'condition'的小样本?这不是强制性的,但它是更好地理解问题:) – RCaetano

回答

1

仅环比条件:

close all 

num = 40; 
date = linspace (0, 4 * pi, num); 
condition = randi (3, 1, num) - 2; 
low = sin (date) - 0.3 * rand (1, num); 
high = sin (date) + 0.5 * rand (1, num); 

for k = 1:3 
    idx = condition == k - 2; 
    c = {"r","g","b"}{k}; 
    line ([date(idx);date(idx)], [low(idx);high(idx)], "color", c, "linewidth", 2) 
endfor 

grid 

enter image description here

+0

也许这对你也很有趣,如果你使用日期/时间:http://wiki.octave.org/Date/Time_functions – Andy

+0

忘记关于时间函数的评论,这是针对另一个线程... – Andy