2017-04-20 41 views
1

我的目標是在外匯市場上顯示隨機震盪指標,爲了驗證哪個參數是最好的設置,我將使用一個滑塊來修改它,並在圖上顯示更新後的結果。如何在八度編碼滑塊來進行交互式繪圖?

我有我的歷史數據,用於定義對(讓說AUDUSD),並加載它之後,我計算Stocastic振盪器:

function [stoch, fk, dk] = stochastic(n, k, d) 
    X=csvread("AUDUSD_2017.csv"); 
    C=X(2:length(X),5); 
    L=X(2:length(X),4); 
    H=X(2:length(X),3); 
    O=X(2:length(X),2); 
    for m=n:length(C)-n 
     stoch(m)=((C(m)-min(L(m-n+1:m)))/(max(H(m-n+1:m))-min(L(m-n+1:m))))*100; 

    endfor 

for m=n:length(C)-n 

    fk(m)=mean(stoch(m-d:m)); 

endfor 
for m=n:length(C)-n 

    dk(m)=mean(fk(m-d:m)); 
endfor 


endfunction 

這是我有什麼,當我繪製STOCH圖片,FK和DK:

Plot based on parameters (14,7,7 as insput

我想補充3個滑塊該圖以改變,在一個範圍內,參數作爲輸入,所以即以具有變化3和50之間的第一參數「N」的滑塊,「k」在2和20之間,「d」在2之間和20.

我會使用UI包在八度,有人可以解決我有一個情節更新時,我使用滑塊?

弗朗西斯

+0

看到我的答案[這裏](http://stackoverflow.com/questions/40570494/minimal-example-of-a-standalone-matlab-gui-app/40570717# 40570717)一個非常簡單的例子 –

+0

@TasosPapastylianou你的例子在八度音箱中不起作用。你試過了嗎? – Andy

+0

@TasosPapastylianou我會看看你的鏈接!非常感謝 –

回答

2

Andy在評論中指出,我鏈接到的示例不適用於開箱即用的八度;這是因爲Octave暫時不喜歡某些東西的嵌套函數,所以我在下面再現了一個'八度版本'。

%%%%%% In file myplot.m %%%%% 
function myplot 

    %% Create initial figure and spiral plot 
    figure; axes ('position', [0.1, 0.3, 0.8, 0.6]); 
    global t; t = linspace (0, 8*pi, 100); 
    x = t .* cos(t); y = t .* sin(t); 
    plot (x, y); axis ([-100, 100, -100, 100]); 

    %% Add ui 'slider' element  
    hslider = uicontrol (     ... 
     'style', 'slider',    ... 
     'Units', 'normalized',   ... 
     'position', [0.1, 0.1, 0.8, 0.1], ... 
     'min', 1,       ... 
     'max', 50,      ... 
     'value', 10,      ... 
     'callback', {@plotstuff}   ... 
     ); 
end 

%% Callback function called by slider event 
%% Also in file myplot.m (i.e. a subfunction) 
function plotstuff (h, event) 
    global t; 
    n = get (h, 'value'); 
    x = n * t .* cos(t); y = n * t .* sin(t); 
    plot (x, y); axis ([-100, 100, -100, 100]); 
end 

enter image description here

+1

不錯的簡答題。順便說一句,我們應該集成一些uicontrol演示核心爲GNU八度4.4 .... – Andy

4

看一看at this demo這將給你喜歡這應該回答你所有的問題,一個窗口:

demo uicontrol

相關部分針對特定的問題是:

h.noise_slider = uicontrol ("style", "slider", 
          "units", "normalized", 
          "string", "slider", 
          "callback", @update_plot, 
          "value", 0.4, 
          "position", [0.05 0.25 0.35 0.06]); 
.... 
noise = get (h.noise_slider, "value"); 

一定要使用Qt工具包!

+0

謝謝你的回覆,看來這正是我所期待的。我會讓你知道我的項目的開發。 –