Creating an active graph that allows variables to be updated in real time.

2 views (last 30 days)
John Carroll
John Carroll on 26 Apr 2022
Commented: John Carroll on 26 Apr 2022
Hello
I am attempting to create a graph that I can update in real time. Currently I plot (see below) F vs D0. D0 pulls a single row from the variable TunabilityD3C and extracts a single point that I define. Here it is the 20th point in the row. It is this point I'd like to actively update. Right now I just manually change the point then rerun the script to regenerate the graph. I'd like to create a slider bar that will change the value of Freq within the range I set then have the graph update in real time as I do this.
Any help is apprieated.
F=[6 10 12 14 16];
Freq = 20;
D0=[TunabilityD3C(1,Freq),TunabilityD3C(2,Freq),TunabilityD3C(3,Freq),TunabilityD3C(4,Freq),TunabilityD3C(5,Freq)];
plot(F, D0,'rs-','LineWidth',2)

Answers (1)

Rik
Rik on 26 Apr 2022
Edited: Rik on 26 Apr 2022
Plot once, and use the callback function of a slider to set the XData and YData properties of that object.
Don't forget to round the value property of the slider to an integer.
I suspect the indexing will be fast enough to just run that code every time. If not, you could pre-calculate the y values for all possible values of Freq and store that in an array.
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!