LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save data in while loop to array

Solved!
Go to solution
Highlighted

Hi everyone, I'm new to LabVIEW. I'm trying to read data using DAQmx and then calculate the center of gravity of each series of data. I read 20 number each time and then do the calculation work. Now I want to output the result to an array to check the stability, but I get into trouble in how to output the results in the while loop. 

Any feedback would be helpful. Thanks.

image.png

0 Kudos
Message 1 of 18
(1,049 Views)
Highlighted

1. No need for a Timed While Loop.  Just change it to a regular While loop and the acquisition will set your loop rate.

2. No need to wire up the N terminal on the FOR loop.  The Autoindexing tunnel will tell the FOR loop how many times to iterate.

3. Your first value in the read array is multiplied with 0, so it is not actually being counted in your calculation.  Is that desired?

4. Since you are using Continuous Sampling, do NOT wire up the Samples Per Channel on the DAQmx Timing VI.  You are just limiting your buffer and increasing the chance of getting an overflow error by wiring it up.

5. There are a few options for building up an array.  Do you want to compare everything while the acquisition is still happening?  Post process?  Do you want to compare every loop iteration's data?  Or just the last X iterations?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 18
(1,013 Views)
Highlighted

Thanks for your advice.

Reply to Q3: Yes it is desired.

Reply to Q5: I want to compare every loop iteration's data. I'm sorry for my poor English. To be specific, I can get 20 numbers of data each time and then calculate the center of gravity. I want to save these results into an array and then output it using the DAQmx write.

0 Kudos
Message 3 of 18
(1,005 Views)
Highlighted
Solution
Accepted by topic author chen3477

@chen3477 wrote:

To be specific, I can get 20 numbers of data each time and then calculate the center of gravity. I want to save these results into an array and then output it using the DAQmx write.


Why not just write the data as you get it?  Then you wouldn't need the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 4 of 18
(998 Views)
Highlighted

Thank you! I'll try it!

0 Kudos
Message 5 of 18
(978 Views)
Highlighted

I added the DAQmx write to the loop but it turned out that it could only output the first data. I need to output the data in each iteration. 

 

Capture.PNG

0 Kudos
Message 6 of 18
(965 Views)
Highlighted

You  need to initialize and start the AO before the loop.  Be sure to clear it after the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 7 of 18
(958 Views)
Highlighted

I tried to make it correct but I failed...

Attached is my code. Could you help debug it?

 

Thanks!

0 Kudos
Message 8 of 18
(954 Views)
Highlighted

@chen3477 wrote:

I tried to make it correct but I failed...

Attached is my code. Could you help debug it?

 

Thanks!


Reread Crossrulz' message:

 

"You need to initialize and start the AO before the loop. Be sure to clear it after the loop."

0 Kudos
Message 9 of 18
(949 Views)
Highlighted

I did move it out of the while loop but it didn't work...

0 Kudos
Message 10 of 18
(946 Views)