From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

moving elements in an array

Hello all.  I have a 1-D array that has 64 elements in it.  I also have a 2-D array of color boxes.  I need to take the elements in the 1-D array and place them in a specific address of the 2-D array.  The 2-D array is 12 col by 6 rows.  Can anybody offer any suggestions on how do this?

Thanks,

Matt Kniller
Nova Research Inc.
0 Kudos
Message 1 of 5
(3,541 Views)
Matt,

The easy part is to use the Replace Array subset function. The tricky part may be deciding what subset to replace. You obviously can not replace an entire row or column of the 2D array with the 1D array. How do the indices of the two arrays map to each other?

Lynn
0 Kudos
Message 2 of 5
(3,537 Views)
Here is a map that I made up for my own sanity.

Col A is the layout of my 1-D array
Col B is address of the 2-D array that the elememt of the 1-D array needs to be moved to.

The picture on the right shows the "2-D array of colorboxes" as it would be shown in LabVIEW.

Message Edited by mkniller on 10-12-2005 08:27 AM

0 Kudos
Message 3 of 5
(3,534 Views)

I don't have LV handy so I can't attach an example, but here's a simple idea:

Store your matrix of indices as a 2D integer array constant on your block diagram.  (Note that you'll need to subtract 1 from them because LV array indices are 0-based.)  Generate a 2D floating point array of the same dimensions and initialize all values to either 0.0 or NaN, depending on the later data processing you'll do.

Pass the integer array of indices into 2 nested For loops using auto-indexing at the loop boundaries.  Pass the 2D floating point array into the loops using shift registers at the boundaries.  Pass the 1D data into the loops without auto-indexing.

Inside the inner loop, use the two loops iteration counts ("i") to extract the appropriate index value from the 2D integer array.  Use that index to extract the sensor value from the 1D array.  Then call Replace Array Subset, passing in the 2D floating point array, the two iteration counts, and the corresponding sensor value.

Just be sure you know which iteration count refers to rows and which one to columns.  My habit has generally been to remember wrong Smiley Sad so I typically make a quick and simple test program to verify which is which.

-Kevin P.

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 5
(3,522 Views)

Here is a sample.  Written in LabVIEW 7.1.1. 

I read your spreadsheet directly and translated the map.  You should be able to restructure it to meet your needs. 

NOTE:  I modified an example from zone.ni.com.  With Office, 2003 I had to modify one of the properties.  It is documented how to change it back if the VI is broken when you open it.

Hope it helps


Paul
Message 5 of 5
(3,509 Views)