10-07-2022 04:46 PM
I'm currently doing some homework, and this seems like the suggested way of putting multiple plots onto a waveform chart.
I'm using a FOR loop with a nice high loop count, a random number generator, and a few shift register terminals to store 4 data points to get turned into an average, and I'm supposed to get both the random numbers and the average plotted together onto one waveform chart. Everything I've seen elsewhere suggests just using a bundle and wiring it to the waveform chart, but as you can see below one of the data types isn't double and its throwing an error.
Question: why is this data type not double? How do I get the data to match so the chart will work?
10-07-2022 09:56 PM
Don't use a picture of code -- attach the actual code (hint -- the file has the extension ".vi"). If you have Controls, make sure we know what values you are using.
Bob Schor
10-07-2022 10:30 PM
Hope to help you.
10-07-2022 11:41 PM - edited 10-08-2022 12:17 AM
(I am not sure why some respond with an xy graph suggestion. This has nothing to do with it).
Seems you want to chart a random number and a 4-point running average. A chart is only correct if you wan to accumulate data forever, keeping a fixed history. If you have a FOR loop, you should use a waveform graph. Make sure you know the difference.
Your code is obviously incorrect: At the first iteration, the random number is not even part of the output. Using an expanded shift register for the running average is NOT scalable and a really (really!!!) bad idea. Whenever you want to change the number of averaged points, you need to rewrite the code and if you ever want for example to average 1000 points, your technique becomes unmanageable. When you use scalable code, all you need is change one integer for the history length. For the first few points you should also NOT divide by 4, because you don't have four points yet. If you want an array of all random numbers, you need to auto index at the loop boundary. The shift register will only return the last element when the loop ends.
Maybe have a look at my presentation from 2016 (part II, slides 12-14 and included code examples) where I show various ways to do a running average.
Your loop will output two 1D arrays (N raw points and N averaged points), so just built them into a 2D array with two rows and wire to a waveform graph. See how far you get. Good luck.