I am trying to update an XY Graph in each iteration of a "For Loop". The only way i can get it to somewhat work is if I place the graph outside my loops and tunnel the data thru. If i place the graph inside the inner loop, it will plot the first iteration, then clear graph, then plot 2nd iteration and so on. I want the graph to plot and update on every iteration ... any ideas ?
Solved! Go to Solution.
The way that graphs work, they clear all previous data and update with the most recent array. You may be looking for a chart if youd like to update inside a for loop. The chart will accept an element data and update the existing data every iteration. Charts have an adjustable history length that can be used to change the displayed length of data and to also limit memory consumption when using a chart.
So if i change my XY Graph to a Waveform Chart , what do i use to convert my bundle to a Wave Chart datatype ?
If you data is a function of time, look at the Nugget by Crossrulz found here that talks about a waveform chart.
If you data is NOT time dependant...
Since there is no such thing as a XY chart, you would have to use shift registers to keep your history data from iteration to iteration and append the updates in the inner loop.
(sorry, posting by phone).
You simply need to substitute an explicit "build array" for the graphs and keep the array of plots in another set of shift register, eliminating the autoindex in you currently have.
Yes, since your x are spaced equally, all you need is a plain waveform graph. Also, since you know the final size of the data structure, initialize it before the loop filled with NaN (they don't graph) and substitute real data as it arrives.
Assuming your x values are actually not equally spaced and the data structures are relatively small, here's a nearly literal upgrade of your code (If the data structures are large, go with the NaN preallocation and replacment with real data as mentioned).
Currently, it updates with each new point in the innermost loop. If you only want to update in the outer loop, place the indicator and "built array" there instead and keep the inner loop all orange.
I would also recommend complex 1D arrays for xy graph. Keeps the diagram simpler.
I appreciate that AltenBach, thats closer to what I need. I guesss I should try and explain a bit more ...
I have some RF Test Equipment and am sweeping from 2GHz to 10GHz in 1GHz increments and recording the output power at set intervals. So my x-axis is my time "points" in intervals beginning at 0, and my y-axis is my output power levels at each frequency point. So my Frequency starts at 2GHz, waits the interval and then records a power, changes to 3Ghz , waits the interval and records, and so on ... Filling in the Data table goes from left to right, top to bottom , this is where i am having issues populating my Graph. I will get one datapoint on each frequency, then it cycles to start over @ 2 GHz ...
OK, so I would initialize a final xy graph data structure (e.g. correctly sized 1D array of clusters, each containing a complex 1D array of the right size, all containing NaN). Place it inside a shift registers of the loop. Now you can replace with real data at any desired position at any time and fill them in any order.