LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bad, Good or Best of Build array function?(2nd attempt)

Hi all,

I would like to learn to use the build array function better in terms of memory usage. I have attached here a snaphshot of my codes on how I normally use the build array function.

I would like feedback from you in order to use the build array function with more efficient but less memory usage.

Thank you in advance,
keng
0 Kudos
Message 1 of 6
(3,092 Views)
keng;

Not exactly related to arrays, but just by looking at your diagram: For what are you using a "For Loop"? It is repeating the same action twice without reason. You can right-click the border of the For Loop and select the remove option.

I think the main problem is inside the vi that read "Dana Sample reading" (Mean.Vi?). If that vi is your creation, then you should look inside it to see if it is possible to combine all the points as an array before outputing them. That way, you will not have so many orange lines.

Enrique
www.vartortech.com
0 Kudos
Message 2 of 6
(3,092 Views)
Actually, the For Loop is doing nothing, not even repeating the same action twice. I think you can safely remove it.
www.vartortech.com
0 Kudos
Message 3 of 6
(3,092 Views)
Besides what Enrique said about the for loop and your subVI, try to eliminate the global variables. Since you've only shown a small portion of your program, it's impossible to say whether they're really necessary. I also wonder why you're using the Insert into Array and not just another Build Array function. It appears that all that you're doing is appending a new row to and existing 2D array. You can wire your old 2D array into the first terminal of the Build Array and the 1D array into the second terminal and get a new 2D array out. You don't have to do the array size function then.
0 Kudos
Message 4 of 6
(3,092 Views)
Hi Enrique,

Yes, I am wrong for that reason. I thought that I could do the insert the elements into the new 2D array once. Well, if I removed the for loop, it still perform of what I want to do.

However, I did not elaborate further of what I want to achieve.

If possible, I hope to seek more help from you.

Here is what i intend to achieve.

If you look carefully on diagram, there is a 2D Global Readings, a Local variable Motor Speed (an indicator) and a 2D Global Data Records.

The 2D array Global Readings has 20 elements in each columns (7 columns). These elements are retrieved from external hardware using a DAQ card. These elements are continuosly replaced every 20 readings.

The DANA Sample Readings.vi is to average all the elements in eac
h columns. Then, the final averaged elements and motor speed data are combined. That is why I use the Build Array Function.

At this point, I use a new 2D array Data Records to store these averaged data on new row every 10 counts. The next set of averaged data will be stored to the next following row in the array.

After I have gathered enough data in the global Data Records, I will saved them automatically into Excel.

To summarise, this is what I intend to achieve. But I would like to get away from "building an array requires allocating and deallocating memory" and try to minimise the use of global variables.

Any idea, now?
keng
0 Kudos
Message 5 of 6
(3,092 Views)
> The 2D array Global Readings has 20 elements in each columns (7
> columns). These elements are retrieved from external hardware using a
> DAQ card. These elements are continuosly replaced every 20 readings.
>

Learning about build array is a good thing, but from the sounds of it,
you may not need to worry about it. For small arrays, when you don't
have a time critical execution deadline to worry about, simple is best.
I'd say that unless your final array has 100,000 elements in it, just
write your diagram the simplest you can.

That means to avoid having places in your code where you read a global,
modify it, and write the data back to the global.

You don't show enough of your program to be able to see the overall
loop, but typica
lly a program runs for awhile and spends most of its
time in a loop. If it is clean, you want to put shift registers on that
loop to hold your 2D array. Then pass the 2D array through the various
case statements and subVIs that can modify it. As stated by others, get
rid of the For loop that does nothing, and try to clean up the subVI
connector. Ideally, you will pass the array into the subVI, it will
modify it, and pass it back out.

Greg McKaskle
0 Kudos
Message 6 of 6
(3,092 Views)