Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

user interface - How to code a slider in Octave to have interactive plot?

my target is to have a plot that shows Stochastic oscillator on forex market, and in order to validate which parameter is the best one to setup it, I would use a slider to modify it and show updated result on plot.

I have my historical data, for a defined pair (let say AUDUSD) and after loading it, I calculate Stocastic oscillator:

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

This is a picture of what I have when I plot stoch, fk and dk:

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

I would add 3 sliders to the figure in order to change, in a range, parameters as input, so i.e. to have a slider that changes first parameter "n" between 3 and 50, "k" between 2 and 20, and "d" between 2 and 20.

I would use UI package in octave, can someone address me to have a plot updated when I use sliders?

Francesco

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have a look at this demo which will give you an window like that which should answer all your questions:

demo uicontrol

The relevant parts for your specific questions are:

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");

Be sure to use the Qt toolkit!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...