LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pad an array with zeros?

I have a 9X1 array, and I want to pad it to a 25X1 array using zeros. I tried using Insert into array, but I can't seem to get it to work.
0 Kudos
Message 1 of 6
(5,950 Views)
Use the "Build Array" function to concatenate your original array and your pad array. Make sure to right-click on the "Build Array" function and select "Concatenate Inputs" otherwise you will build a 2D array, instead of concatenating two 1D arrays.

Good luck,

-Jim
0 Kudos
Message 2 of 6
(5,950 Views)
Here's one VI with 4 (count 'em 4) ways to do the same thing. The bottom one would be the most efficient--especilly if the size of the padded array came from a constant rather than a control.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 6
(5,950 Views)
And there is a fifth, the most simple one: Use "Reshape Array" with the new size.


LabVIEW, C'est LabVIEW

0 Kudos
Message 4 of 6
(5,950 Views)
The fastest way to do it is to use the initialize array function to create a zero-filled array of the final size and then use a replace array subset function to insert the whole 9X1 array into it in one operation...(see picture)

Using build array, inserting one array at a time, reshaping etc. is generally slower. In this case the array in question is too small for it to matter though, at least as long as your not repeating the operation extremely often.
Message 5 of 6
(5,950 Views)
That's one element at a time...off course.
0 Kudos
Message 6 of 6
(5,950 Views)