02-03-2007 04:36 PM
02-03-2007 05:18 PM - edited 02-03-2007 05:18 PM
The two simplest methods are probably like this. They have subtle differences which will only be relevant in the case of very large arrays (one of them being that the second method was wrong, so I removed it but you can just use the first one).
To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).
Message Edited by tst on 02-04-2007 01:24 AM
02-03-2007 05:50 PM - edited 02-03-2007 05:50 PM
(Tst, I agree with that solution. The one you just deleted was wrong. :D)
However, I despise input terminals inside loops, because data could change at an arbitrary iteration while the loop executes, giving unpredictable results. 😉
If you place the 1D array terminal before the loop as shown in this image, there will also be a performance advantage, important for large datasets (not important here with a 3x3 array). (1) The terminal only gets read exactly once instead of at each loop iteration (an expensive operation involving the UI!) and (2) the compiler can fold the 1D array into a constant during the loop execution (see the grey outline showing folding in LabVIEW 8.20?).
Message Edited by altenbach on 02-03-2007 03:53 PM
02-03-2007 07:08 PM - edited 02-03-2007 07:08 PM
Message Edited by altenbach on 02-03-2007 05:11 PM
02-04-2007 01:55 AM
@altenbach wrote:
(Tst, I agree with that solution. The one you just deleted was wrong. :D)
What are you talking about? I don't see any other solution...
However, I despise input terminals inside loops, because data could change at an arbitrary iteration while the loop executes, giving unpredictable results. ;)
That was just for clarity (remember the Display Terminals as Icons thing?), because I found some people have trouble seeing auto-indexing tunnels. I definitely agree with you on this point. Also, the transposition (If I remember correctly) is also an expensive operation because it has to rearrange the data in memory (I think, needs to be tested).
02-04-2007 03:15 AM
I consider these LabVIEW minaitures what some might call "Fingerübungen" for the LabVIEW programmer. It's all fun. 🙂
I simply hope that it will peak the interest of some aspiring programmers that happen to pass by. Practical examples are the only way to learn well about loops, tunnels (autoindexing and otherwise), and the fundamental truth that there is always more than one way to do things.
I've never tested the speed diffference between slicing out a row vs. a column, but my gut feeling tells me that a row (= autoindexing) is probably slightly better because elements in a row are immediately adjacent in memory, while elements in a column are spaced apart.
The OP gave us an exceedingly simplistic case with a square 2D matrix, but all our solutions also work for the general case where the 2D array can be of arbitrary size. The 1D input array must match the column size and the result will match the row size.
02-04-2007 03:46 AM - edited 02-04-2007 03:46 AM
If only the final result is important to you, consider the following solution too!
A new Item for the wish list: I wish there was a property for auto-indexing node, asking the user on which dimention it must act. therefore we didn't need to transpose the input array and make a new copy of it, spending a lot of memory space and time. Although there may be some way to create the input 2D array transposed in the earlier stage, where it is built.
Message Edited by Soroush on 02-04-2007 03:47 AM
02-04-2007 03:56 AM