12-24-2012 09:30 PM
I have a matrix M of size 5 by 8 and all the elements of this matrix are either one or zero.
I want to generate a pair of random number, one for row index (between {0,5} ) and other for column index (between {0,8} ) such that the pair generated
doesn't map to the elements zero of matrix M. The pair should only map to unit elements of M.
How to do this in labview.
Thanks
12-24-2012 10:14 PM
Use the random number function to generate the row number, and another to generate the column number (multiply by 6 or 9 respectively, and round down to the nearest integer, the floor function.)
Determine if the resulting row and column gives you a zero. If it does, repeat until it gives you a one.
12-24-2012 11:53 PM - edited 12-24-2012 11:53 PM
Thanks for your reply.
That is fine. But if the number of zeros in the matrix is very less, then the program takes very long time to generate appropriate random numbers.
Is there any solution to this problem ?
12-25-2012 12:44 AM
If your matrix is only 6 x 9, that's only 54 possible combinations. A loop will run so quickly, it's going to hit a 1 before you know it.
What are you really trying to do? The question you posed is very odd. It sounds more like a homework assignment rather than a real problem.
12-25-2012 03:23 AM
Actually the matrix is of bigger size (about 24 by 36) and the number of unit elements in it is vey few (say 25).
And I have to generate an appropriate pair of random number in real time.
12-25-2012 12:16 PM
Then why'd you say 6 x 9? 24 x 36 is still not very big. Why don't you try programming it with the instructions I said and see how it turns out.
What do you mean by "real time"? In computers, real time means something very specific. A real time operating system means it is running deterministically and the CPU cycles are guaranteed to run in an alotted time. This can't happen on Windows, Apple, or Linus OS's where the OS can steal CPU cycles to take care of other tasks.
12-25-2012 10:53 PM
Thanks for your reply.
My experiment is a feedback system. I acquire data from a PXI-5124 digitizer and perform some calculation and then send the feedback signal to a second monitor. Finding a pair of random number appropriately is a part of calculation, so I need to do it quickly.
12-25-2012 11:42 PM
How often does the matrix change?
12-26-2012 12:03 AM
The matrix does't change in one experimental session. It is specific for every experiment.
12-26-2012 12:44 AM
How quickly is "quickly"? Would milliseconds be fast enough?
Have you tried coding yet to see how quick it can be? This is a simple enough problem. You could have coded it and tested in the time it has taken you to keep reposting!
If the matrix doesn't change during the experiment, then you could go through the array at the initialization process and determine which elements have a 1, how many there are, and then sort out the coordinates for each of those 1'. (You are still talking only milliseconds.) Then during the test, do a random number generation to pick out a set of coordinates from your list. (Which is as quick as you can possibly determine a random number. One shot!)