LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving data after specific increments

Solved!
Go to solution

Hello Everybody,

 

Again i am here with a basic question. I am working on saving/writing encoder data. In order to practice i am generating random numbers from 0-1000. What i want is to write the data in excel or CSV after fixed increments of 3 (just for practice but that can be a varible and can be later set by the user). Such that  at the end i have 3,6,9,12,15........ in the data.

 

Can you people help me and put me in right direction as what would be the best approach to achieve that. Thanks for the time

 

0 Kudos
Message 1 of 3
(2,799 Views)
Solution
Accepted by topic author acuteboy

This is probably some of the simplest code to do that task that doesn't involve Express VIs.

 

mod3.png

 

You can see the first loop generates the numbers 0...999. Perhaps you want to add 1 to that value (you can do this in the array using increment, or adding a constant 1, or after the array. Increment and Add both work with individual numbers and arrays of numbers.

 

The second loop checks to see if the result of x/3 has a remainder of 0. It then uses a Conditional Tunnel with Indexing behaviour, to output an array of numbers, only when the condition is true.

 

Then, the code uses Build Array to make the 1D array 2D. It's still just one row of all the values. The next function is Transpose 2D Array, which makes it 1 column.

 

Then, the Array to Spreadsheet String function places an End of Line character after each row (i.e. after each element). If you wanted to have all the elements in one row, you can remove the two previous functions and then they will have commas in between them, as specified by the Delimiter field at the top of the function. 

 

Finally, the string is passed to Write to Text File. Since I didn't wire a path to the function, it will pop up a dialog box, asking you to choose a place to save the file. You can call the file whatever you want, but adding a ".csv" extension will help Windows recognise its type.


GCentral
Message 2 of 3
(2,779 Views)

Thaks a lot. As i said later the random generator will be replaced by encoder position. So i will work on this and come back if any issues. 

0 Kudos
Message 3 of 3
(2,773 Views)