LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averages for number of loops

Solved!
Go to solution

Hello everyone,

 

I have a code (attached) in which a triangular wave is supposed to ramp a magnetic field up and down with very low frequency (0.1 Hz or low). Field reading (X) vs. keithley reading (Y) represented by two random number generators have to be taken in synchronization with the triangular wave point by point. I would be very grateful if you could help to achieve the following:

 

1. Taking the average for few cycles. Basically, I would define the number of loops in the outer For loop and the sampling number in the inner While loop and then take the average between loops.

 

(Data for loop1 + Data for loop2 + .....+Data for loop n)/n

 

 

 

2. The averages should be written to text file and at the same time I hope I still get the whole date in the measurement file.

 

 

Thanks,

 

Hadi

Islam means peace
0 Kudos
Message 1 of 23
(2,749 Views)

Please post your code in 2009 version

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 23
(2,742 Views)

Hi Anand,

 

Here it is. Thanks for help.

Islam means peace
0 Kudos
Message 3 of 23
(2,738 Views)

You are running a while loop inside a for loop is not a good idea you can use nested for loops instead and can give some defined numbers of execution. Use of build array inside loop will consume lot of memory so it is not recommended. You can use your auto indexing tunnel to build the array and find the average and also gather all the measurment data. Take a look at the attached snippet.

 

 Build data.png

 

This is just an idea to start a easy code.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 23
(2,729 Views)
Solution
Accepted by topic author Hadiq

Assuming that you want to monitor the data as it arrives, I would initialize several arrays, two to keep the x and y data and one to keep the count of each "bin".

 

Now simply add the new data to the current elements while incrementing the corresponding count. Dividing by the count will give you the average to be graphed. Here is a simple rewrite. The "sampling should correspond to the size of the field ramp, so it should not be a seperate control, I think. Currently, you graph the two random channels. DO you rather want to graph them both vs the field instead? Do you want to average the forward and reverse scans individually or should they go to the same average with a data array of half the size?

 

You save operation seems still a bit convoluted. How do you actually want the data to be organized in the final file?

 

Here's a quick draft to get you started.

 

 

 

0 Kudos
Message 5 of 23
(2,724 Views)

Many thanks Altenbach for the nice editing. It is what I am looking for. The two random number generators are assuemd to be the data to be collected when the expermient is conducted. You are right about the saving data. I am trying to save the data in coloumns as follows : X   Y   Average X    Average Y but it seems that I have to do alittle change for correcting it.

 

Thank you so much for your help.

Islam means peace
0 Kudos
Message 6 of 23
(2,714 Views)

Hi Altenbach,

 

Could you help me in sorting out the last bit of the code you edited. Just want the data to be sorted in columns as follows:

 

X        Y           Average X         Average Y

 

Many thanks indeed for your help.

 

Hadi

Islam means peace
0 Kudos
Message 7 of 23
(2,687 Views)

Hadiq wrote:

Could you help me in sorting out the last bit of the code you edited. Just want the data to be sorted in columns as follows:

 

X        Y           Average X         Average Y


I think  there are N columns for X and Y (plus two for the averages), so I don't quite understand your description.

0 Kudos
Message 8 of 23
(2,677 Views)

Yes you are right. However, the data seems to be quite merged and classified into two long rows (horizontally). something like the follwing

 

X-  Y-

11111111111111111111111

11111111111111111111111

 

 

I therefore would like to classify it into four columns to make it easy for me when edit it using excel. To be clear, the data has to be as follows

 

 

 

 

X Y      X ave         Y ave

 

1 1      1                1

1 1      1                1

 

 

Islam means peace
0 Kudos
Message 9 of 23
(2,671 Views)

Hi Altenbach,

 

When I remove the outer loop, I get the data classified into 4 columns but the averages do not work as there are replications of X and Y data instead.

 

please see the attached photo

 

 

Islam means peace
0 Kudos
Message 10 of 23
(2,640 Views)