LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

insert randomly generated number into n by n matrix with keeping previous ones

 Hi I am new in Labview. I have a problem. I want to insert randomly generated number into n by n matrix with keeping previous ones with starting first row's first column then second column and so on.Then start from second row and so on.. How can I make it? I tried but every time it generated at the same time and continuosly changing variables. For example 10*10 matrix? Regards. 

0 Kudos
Message 1 of 12
(4,177 Views)

hi there,

your problem description is (at least for me) contradictory.

or you are just unspecific.

 

what is you initial condition?

what is your desired result?

what would describe each step?

 

do you know how to iterate over a matrix/array?


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 2 of 12
(4,164 Views)

Hi, thanks for replying. Firstly I generate continuously number and ı want to keep it in the matrix. first generated number goes to first row first column. the second one goes to first row second column. By the way we know how many rows and columns we have. For example we have 10*10 matrix. at the 10th number goes to first row 10th column. The eleventh one goes to second row first column and so on. the last 100th number goes to 10th row 10th column. While it is happening ı want to store what ı get before one by one as ı told above. Then ı want to plot this x and y graph. x is for rows y is for columns. My desired result is 10 by 10 matrix consist of these generated numbers. I want to keep one by one each generated number. İnitial condition is empty 10 by 10 matrix and ı want to fill it step by step. Actually ı dont know certainly how ı iterate over a matrix. Regards. 

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

I said wrongly. I know a little bit about how to make array or matrices and ı have emergency. Anybody who helps me?

0 Kudos
Message 4 of 12
(4,122 Views)

Hi sheriffff,

 

to keep values from one iteration of a loop to the next iteration you should use a shift register.

This is pretty basic LabVIEW stuff taught in the beginner courses offered for free by NI.

 

Have you tried using them?

 

General hint: When you need help with your VI you need to attach this VI to your post…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 12
(4,114 Views)

Yeah you are right,I know that hint but my VI is completely out of function.Thats why I didnt add that. And I tried this. That is why I came here.

0 Kudos
Message 6 of 12
(4,105 Views)

And still I can not make a general diagram.

0 Kudos
Message 7 of 12
(4,097 Views)
0 Kudos
Message 8 of 12
(4,085 Views)

create for-loop that runs MxN times, inside the loop generate random number into an indexing tunnel,

afterwards reshape the array to a 2D-array of MxN dimension.

 

if you really need a Matrix, you can then cast the 2D-Array to Matrix Type.


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 9 of 12
(4,075 Views)

LabVIEW has "structures" (For, While, Case, etc.) and "functions" that generate values which are carried on "wires".  In LabVIEW, if you have a Structure with a function (or a Constant) inside it that generates a value, you can bring that value outside the Structure by creating a wire and wiring it to the right edge of the Structure, where it becomes a "tunnel" to bring the values out.

 

By default, a For Loop output tunnel is an "Indexing" tunnel (if you look at it carefully, its symbol is an open box with the characters "[]" (suggesting array indices) inside it.  This means that if you generate something (a number, a path, a string, a cluster, an array, etc.) and wire it to the right edge of the For loop, it will be turned into an Array element, one for every For iteration.

 

In particular, if you generate a number inside a For loop, you'll get a 1-D array of numbers.  If you generate a 1-D array inside a For loop, you'll get a 2-D array of numbers.  What happens if you generate a 2-D array inside a For loop?  [I'm hoping you don't need me to tell you the answer ...].

 

Generating a 2D array of random numbers is simple.

2D Random.png

If the number of rows and columns is "small" (meaning less than a million), the chances that two array elements are identical is miniscule (but could still be tested -- think about how to "efficiently" test this).

 

A much more interesting question is to generate different random numbers when the numbers are all integers, and when the choice of numbers is small enough that choosing the same number twice is not improbable (I love double-negatives!).  Think about how to choose the 10 numbers from 1 to 10 "at random" and try to come up with a good algorithm.

 

Bob Schor

Message 10 of 12
(4,062 Views)