ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating within a for-loop

Solved!
Go to solution

Hello!

 

I have an 2D array that i process within a for-loop. The array consist of two columns, one for the date/time stamp and one for the corresponding data measurements.

What I need to do is to loop through the array at one point at a time, and calculate the mean from time t to time t+n (n is a set value, i.e 10 min). I think i pretty much have got the code right, but I need some help to finish it.

 

The pseudo-code should look something simple as this:

 

for time t to time t+n

calculate mean

 

By the way, the time between the measurements is not fixed, so I need to use the time and not the number of datapoints.

 

Greetings

Kristoffer

0 Kudos
Message 1 of 10
(4,389 Views)

Hi Kristoffer,

 

your pseudocode should look as simple as this:

 

for all items in array

   if time in range then add value to array2

next item in array

average array2

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(4,288 Views)

Thanks Gerd!

 

I was thinking that it might end up with something like that. May I ask if you have some example code or something? As I am having a bit of trouble with realizing the pseudo code..

 

Greetings

Kristoffer

0 Kudos
Message 3 of 10
(4,282 Views)
Solution
Accepted by topic author Sjefsgjogleren

Hi,

 

you should try something like this:

Rodéric L
Certified LabVIEW Architect
Message 4 of 10
(4,269 Views)

Thanks! Seemed to help me some way along the road!:)

 

Maybe I did not explaned the whole problem good enough.

I need to find the interval (of i.e. 10 min) with the lowest mean in my data. That means that i need to take time instance 0 (element 0 from the time/date column) and calculate the mean for the coming interval. Then I need to do the same for the next intervall and so on. To be able to find the lowest mean i guess all means should be saved to an array? It would also be easier to process the mean data later by doing that i guess?

 

Your code helped me a lot Rodèric, but I cant get it to work 100%. I seems like it doen't wont to update the mean continousley.

I have included my program as well as some test data, really really hoping that you or someone else can help me a bit further on this one!:)

 

Greetings

Kristoffer

Download All
0 Kudos
Message 5 of 10
(4,261 Views)

Actually, think I solved it now! Thanks a lot for the help guys!:D

 

Greetings

Kristoffer

0 Kudos
Message 6 of 10
(4,211 Views)

you're welcome

Rodéric L
Certified LabVIEW Architect
0 Kudos
Message 7 of 10
(4,151 Views)

Seems like I maybe was a bit fast on this one, as I am still struggeling to calculate the moving average. As I am only processing one data point to the mean.vi pr iteration the mean.vi just returns the same number as it gets in. Any suggestions on this one?:)

 

Greetings

Kristoffer

0 Kudos
Message 8 of 10
(4,140 Views)

Hi Kristoffer,

 

I would suggest to calc the mean using more than just one value!Smiley Wink

I would also suggest attaching the current VI you're working on...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(4,134 Views)

Hehe;) well, i kind of figured out that one, just could figure out how!:P

I have now attached a test dataset and the program;)

Download All
0 Kudos
Message 10 of 10
(4,131 Views)