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: 

Build coordinates matrix from 2 vectors

Hi!

 

I'm trying to build a matrix of coordinate positions to go to, for a scanning application.

 

Right now, I managed to use labview to build me to matrix/arrasy containing the individual x, and y coordinates.

now I want to append them together, for all possible permutations.

 

eg : 

x = 0 1 2 3 4

y = 5 6 7

 

make a new matrix/array containing

0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

5 5 5 5 5 6 6 6 6 6 7 7 7 7 7

 

This is a trivial thing to do in c++, or matlab, but I am stumped on how to to do it on Labview.

Anyhelp would be appreciated. Thanks!

 

eg code

n=1

for ii=1:length(y)

for jj=1:length(x)

output(n) =[x(jj) y(ii)]

n=n+1

end

end

0 Kudos
Message 1 of 12
(3,059 Views)

Well, looking at your text code, there are two FOR loops, so simply duplicate this. 😉

 

 

 

 

I don't know what you mean by "coordinates". The above creates complex numbers. Replace RE/IM to complex with a "bundle" or with a "built array" to get other data types (of course you need to initialize the shift register accordingly). You can also create two 1D arrays the same way.

0 Kudos
Message 2 of 12
(3,051 Views)

Use nested for loops just as in text languages. For optimum memeory allocation initialize the output array outside the for loops and use Replace Array Subset inside the loops.

 

Lynn

 

Coordinates..png

Message 3 of 12
(3,050 Views)

Since you are doing the Cartesian Product I will also point you here for a general solution.

 

http://forums.ni.com/t5/LabVIEW/3-loops-incrementing/m-p/1439422#M552998

0 Kudos
Message 4 of 12
(3,035 Views)

Thanks for all your input guys!

 

johnsold, thanks for that. It's what I needed.

I'm suprised however that nothing is needed in the first loop other then the other loop?

How does it work? I thought you would have to pull out the index of my x based on the first loop, and then the index using the second. I guess the answer was simpler then I thought.

 

Darin, thanks for that, now I know what my problem is called. Cartesian product. I had no idea 😛

0 Kudos
Message 5 of 12
(3,028 Views)

The indexing is sequential so I just added one to the previous index.  You could do some math on both indexes and get the same result, but his seemed straightforward.  It is also what your MATLAB code does with n.

 

Lynn

0 Kudos
Message 6 of 12
(3,019 Views)

I wasnt aware of the whole "enable indexing/disable indexing"

 

I only noticed when I was comparing my copy to yours, and saw that they where diferent colors.

At first I was using "index array" trying to pull out one value in the first loop, and the second in the second loop, but I was getting plenty of data type mismatch.

(As you can tell, I'm a labview newbie)

 

Now that I know how to use for loops the proper way... watch out 😉

0 Kudos
Message 7 of 12
(3,014 Views)

Autoindexing is one of the cool LabVIEW features. Notice also that if you are autoindexing, you don't need to wire N because LabVIEW simply uses the size of the autoindexing array.

 

0 Kudos
Message 8 of 12
(3,005 Views)

NI has some on-line tutorials to help you get started with LV.  It may be worth the time it takes to work through them in reduced frustration and improved productivity.

 

Lynn

0 Kudos
Message 9 of 12
(3,004 Views)

For fun with autoindexing, see if you figure all the subtleties in this code (which has the same result as Lynn's, but transposed). 🙂

 

 

0 Kudos
Message 10 of 12
(3,001 Views)