09-30-2011 09:55 AM
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
09-30-2011 10:27 AM - edited 09-30-2011 10:35 AM
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.
09-30-2011 10:27 AM
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
09-30-2011 11:41 AM
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
09-30-2011 01:38 PM
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 😛
09-30-2011 02:44 PM
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
09-30-2011 02:58 PM
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 😉
09-30-2011 03:40 PM
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.
09-30-2011 03:41 PM
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
09-30-2011 03:53 PM - edited 09-30-2011 03:53 PM
For fun with autoindexing, see if you figure all the subtleties in this code (which has the same result as Lynn's, but transposed). 🙂