math

Running Total with Sample and Hold?

ginsu777's picture

I have been trying to take a single sample every 15 seconds from a number I am calculating and then display as it increments every minute - only incrementing when it gets to the next whole number. The reason for this confusion is that the number is calories/minute based on a heart rate that is sampled every 2 seconds. So I only want to calculate and store and augment the number every minute.

In any event, I tried the INTEGRATOR patch, but it seems to go haywire adding things up fast. I also tried different multiplexers and triggers but with no luck.

Any ideas how to calculate and display a running total sampled from a stream of calculated numbers? Side issue: rounding. The numbers calculated are usually like 0.0254689 every 2 seconds I dont even want to count it towards the total unless it reaches something like .20 or .30

The included example wont work unless you can input some numbers on the serial port or replace the serial thing with some numbers of your own.

Mathematical Expressions: Snapping to a value

hob's picture

Hi guys,

I'm not so hot on my maths, can anyone explain how I might accomplish the following in QC?

I have a slider input from -0.8 to 0.8. However, I want the output to jump up in 0.2 increments. This could be achieved with the Mathematical Expression patch, right? I'm just not sure how to use MAX/MIN etc...

add and derive average using javascript and structures

Swiftlikeninja's picture

Let me start off by saying that I am a complete noob when it comes to javascript. Id imagine that this should be easy to accomplish.

I would like to know how to take a structure and add up all the values then divide the total by the structure count providing me with an average. Currently I am accomplishing this with a rather ugly and lengthy set of structure makers to a math patch but its not dynamic, and is pretty sloppy. To go one step further I would like to be able to add up all of a certain sub index within a complete structure through javascript. Im not concerned with maintaining the original structure, the only output needed is the average value.

Im not asking anyone to make this for me but again im lost when it comes to javascript and would appreciate any assistance. Ive dugged through the post to attempt to find an answer got nowhere. Ive checked cybero's reference site but cant figure out what to combine to achieve what I need.