09-23-2012 03:30 PM
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
Solved! Go to Solution.
09-23-2012 03:37 PM
Please post your code in 2009 version
09-23-2012 03:42 PM
Hi Anand,
Here it is. Thanks for help.
09-23-2012 04:08 PM - edited 09-23-2012 04:08 PM
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.
This is just an idea to start a easy code.
09-23-2012 04:37 PM
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.
09-23-2012 04:57 PM
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.
09-24-2012 04:05 AM
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
09-24-2012 04:51 AM
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.
09-24-2012 05:05 AM - edited 09-24-2012 05:11 AM
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
09-24-2012 09:27 AM
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