Storing a stream of float values in an array?

Hi,

I’m building an application that takes in sensor data from an arduino, I’d like to run some smoothing on the data and to do so I need to store a certain timeframe of values in an array.

So how can I store the last 10 values sent, in an array, and then append the newest value in once we reach 10 values and kick out the oldest?

Thank you.

EDIT: I found a flaw with my approach. Use HarryHighDef’s way instead.

You can implement a QUeue by wrapping a little logic around an array, adding a Queue function and a Dequeue function. Queue function simply adds the next value onto the end of the array.

Dequeue function returns the item at 0 index and removes it and resizes the array.

this is one way to do it. it looks backwards but should work for a first in first out buffer like you want.

Hey thanks for responding,

I’m familiar with the concept (i’ve used it in python), but I’m not familiar with writing C++ with the engine.

Is there a way to accomplish this with blueprints?

Yes, If you make an array of floats and add to it every time you get your sensor data then check if it is longer than your queue length, say 10, if it is longer remove the element at index 0 until it is short enough.

I think a syntax example is needed.

I recommend using HarryHighDef’s method. Make sure you remove the item not just set the index to empty.