LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using array subset with for loops

Solved!
Go to solution

I have a 2D array (m * n) and I want to examine a subset of this array (x * y). I'm having some problems using the array subset function in doing this. If I want to iterate through 'y' columns containing 'x' elements, I thought I could use a for loop with the array subset function inside but the resulting array I get is actually one populated by the diagonal elements of my original array. I have attached my current VI which hopefully explains things.

 

For example, if I load an image which is 800px * 600px then my program creates a 800*600 array and each element is the maximum out of the Red, Green and Blue pixel value. Then, I want to look at the first 320px * 600px (i.e. a subset of the array with size 320*600). So how would I use array subset correctly to generate this 2d aray? My aim after this step would be to perfom some elementary mathematical calculation such as averaging on the subset.

0 Kudos
Message 1 of 8
(4,426 Views)

I don't have IMAQ so your VI comes up pretty broken but I can see your array handling.  I don't understand why you're using the For Loop.  You can access both dimensions of a 2D array directly using the Array Subset function.

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 8
(4,421 Views)

Hi Kelly,

 

Sorry about the IMAQ mess!

 

Ah ok so I don't have to iterate with array subset? I'm not sure how to wire up the indicators in this case: I tried setting my first index and length to 0 and 320, respectively, and then setting the other pair to 800 and 320, respectively. I guess that's not correct as I don't get the correct subset out!

0 Kudos
Message 3 of 8
(4,413 Views)

You've almost got it.  You want to set the second index to where you want to start not the end of the array.  If you want the final 320 pixels then you'd set the index to 799-320 or 479 (remember that arrays are zero indexed so an array with 800 elements has indexes from 0 to 799).  You can then not wire the length which defaults to the rest of the array.  If you start at any other place in the array you need to wire the length unless you want everything else.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 4 of 8
(4,394 Views)
Solution
Accepted by topic author alphalaura

arrray subset.png

 

Does this do what you want?

_____________
Creator of the BundleMagic plugin for LabVIEW!
Message 5 of 8
(4,390 Views)

Aha, thank you both - that really helps and now I'm getting the correct numbers.

 

(Can I mark both replies as the solution?!)

0 Kudos
Message 6 of 8
(4,360 Views)

@alphalaura wrote:

 

 

(Can I mark both replies as the solution?!)


No just pick the one most applicable and give kudos to both (if you haven't already).  The fact that you are even trying to thank correct answers and give kudos, puts you far above the majority of users on this forum.

0 Kudos
Message 7 of 8
(4,344 Views)

That was a tough decision! Kudos given to both littlesphaeroid and kbbersch 🙂

0 Kudos
Message 8 of 8
(4,335 Views)