LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Random selection of rows from a 2D array then subset both the rows that were selected and those that were not. Please see message below.

For example, I have a 2D array with 46 rows and 400 columns. I would like to randomly select 46 data rows from the 2D array. By doing the random selection it means that not all individual 46 rows will be selected some rows may appear more than once as there may be some duplicates or triplicates in the random selection. The importan thing is that we will have randomly selected 46 rows of data (no matter that some rows appear more than once). Then I would like to subset these randomly selected 46 data rows (some which will be duplicated, or triplicated, etc.) and then also find and subset the rows that were not selected. Does this make sense? Then i would like to do this say 10 times for this data set. So that then I will have 2 by 10 data sets: the first 10 each with 46 rows and the other 10 with n rows depending on how many WERE NOT randomly selected. i hope that my explanation is clear. I am relatively new to Labview. It is really great so I am getting better! If anyone can help me with this problems it will be great. RVR
0 Kudos
Message 1 of 6
(3,197 Views)
Start by generating randon #s between 0 and 45. Run a for loop X times and in it use the random function, multiply the result by X and round down (-infinity). You can make this into a subVI, which you can reuse later. In the same loop, or in a different one, use Index Array to extract the rows which were selected (wiring the result out of the loop with auto indexing causes it to be rebuilt into a 2D array).
One possible solution for the second part would be to go over the array of randomly generated numbers in a for loop and use Search 1D Array to find each of the numbers (i). If you get -1, it means the row wasn't selected and you can extract it.
I hope this puts you on the right path. If not, don't be afraid to ask more.
To learn more about LV, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide.

___________________
Try to take over the world!
Message 2 of 6
(3,195 Views)
Hi tst,
thanks for the help. Could you take a look at this vi I made and tell me where I am going wrong? I will also send you the data file in the next message. else you can use any 2D array. i hope that you can help me. Thanks for all the advice. I will certainly do some of the things you suggested.
0 Kudos
Message 3 of 6
(3,184 Views)
I made the mods I originally described to your VI. Compare it to what I wrote and you will see what I mean.
A couple of comments on your code: the outer for loop is completely unnecessary, and the way you wired the -1 VI is very dangerous, because you connected it "backwards". A clean (and documented) diagram is very important.
Also, if you post any more code, please backsave it to 7.0 (File>>Save with Options).

___________________
Try to take over the world!
Message 5 of 6
(3,178 Views)
Hi tst
thank you very much. I am aware that my coding is not-yet the best. I need to first plan then execute. i usually just jump straight into it and perhaps that is not the best way to do things.

That works very well. Thank you. One thing...I do need the outside for loop so that I may create the various data sets. so what i did is I wired the 'array size' vi together with the 'indexing' vi and wired this to the 'generate X rand' loop so I am sure to always get 46 random selections. Then I put the outside for loop and wired the numeric control to it so that i then decide how many data sets i produce from this single data set.
Anyway, thanks for your help and your advice.
Best wishes,
RVR
0 Kudos
Message 6 of 6
(3,166 Views)