LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Truncating an array within a for loop

I'm currently working with a program that builds an array of 3000*N real numbers, where N is a control that I specify. I want to pass this array into a for loop that runs N times, each time splitting the first 3000 numbers of the array. So, in other words I want the for loop to execute enough times such that the initial array will be completely divided into groups of 3000 when I'm finished. Later I'll be finding the maximum value of all of these subarrays and taking the average of those. What I tried first is to pass the array into the for loop, then truncate it at index = 3000, but the problem is that I can't hard code the loop to do this N times. Any advice or other methods you'd recommend for doing this?

Thanks.

Message Edited by Robtn on 03-05-2010 03:17 PM
0 Kudos
Message 1 of 6
(2,659 Views)

Is there a particular reason you aren't doing this using a 2D array?

 

If you stick with a 1D array than you can always divide the total length of the array and calculate your value of N. Then you can use a nested FOR loop with the outer loop running N times and your inner loop running 3000 (or whatever size you need) times. Use a shoft register on (on both loops) to keep track of your current index into the 1D array.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 6
(2,649 Views)

Attached is an example of what I think you need.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 6
(2,640 Views)

Mark--I don't think I can use that approach. Let me be more specific on what the problem is:

 

Our "big program" is a giant while loop that constantly reads in voltage values from a DAQ assistant.

 

It has two modes, the first of which I'm having a lot of trouble with. This mode uses a for loop (N = 3000) nested within the giant while loop.

When the for loop activates, the DAQ assistant takes reads 300 samples for every iteration and takes the maximum of those 300 values. It then builds an array composed of all the maxima. After the for loop has executed 3000 times, a case structure activates, which then finds the maximum of the array of maxima.

 

I want this (N=3000) for loop to execute an arbitrary number of times, a number that I will specify. Each of those times it should generate a completely seperate array of maxima. So, if I want the for loop to run 5 times, I want 5 different arrays.

 

My approach for doing this was to change N=3000 to say N = 15000, then split up the resulting array 5 times. So, I need an entirely separate for loop that reads in this array of 15000 maxima on its own and splits it 5 ways. I think what you're suggesting is to use a for loop outside of the N=3000 loop, which is a good idea in theory, but experience has shown that this will not generate 5 separate arrays. It will actually concatenate each array into one, hence the problem we currently have.

 

Yik--I won't have access to Labview over the weekend. Is it possible to take a screenshot and post it, or maybe a short description?

 

Thank you for the responses.

0 Kudos
Message 4 of 6
(2,626 Views)
This probably isn't the answer you want to hear but perhaps you need to take a serious look at your application and do some clean-up or refactoring of the code. From your description it sounds like it is poorly written code that is difficult to maintain. If this application will need to be around for quite some time and is a vital part of your testing there is benefit from reworking things to make it more modular, readable and maintainable. Also, without seeing your code there is no way we can make specific suggestions on how to solve your problem in your current code.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 6
(2,621 Views)

Attached is a picture version.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 6 of 6
(2,606 Views)