LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fill out a 2 dimensional array with random numbers

Hi everybody!
I would like to fill out a 2-dimensional array (size variable, user can
enter it) with random numbers. First I would like to fill the first column
and then the second and so on....Then I would like to write this array to a
text file, so it looks like a table.
I tried it with two "while-loops", but it won't work. Can anybody help me
and perhaps send me an example-vi?
Thanx a lot,
Oliver.
0 Kudos
Message 1 of 6
(9,547 Views)
Hi Oliver,

I think you have two numeric controls and a "generate" button on the front panel. When generate was hit do the following:

Use "initialze array" to generate a two dimensional array using the numeric controls for the sizes and a contant of the data type you want here a DBL.

Create a For loop. Create a shift register and connect the array to the shift register. Connect one of the numeric controls to the N.

Inside this loop create another For loop with a shift register. Connect the shift register from the outer loop to the shift register and the iteration to this loop. Connect the other numeric control to the N.

Inside the second loop generate your random number, use Replace Array Element with the two iterations connected to the indexe
s. The input and output of Replace Array Element is connected to the shift registers.

At the right shift register of the outer For loop you get the array with the random numbers. Then use Write to spreadsheet file.vi.

I hope this helps
Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 6
(9,547 Views)
try this file. it was saved in 6.1 format.
0 Kudos
Message 3 of 6
(9,547 Views)
Hi unclebump,

your solution is easier to implement but has an impact on performance.

Your inner For loop will generate an one-dimensional array for each iteration of "channels". So you need a lot of memory allocation. The data have to be moved to the two-dimensional array (maybe its only a pointer).

The terminal of "datapoints" is in the outer loop so LV cannot calculate the amount of memory it needs for the two-dimensional array, since running the "channels" the value of "datapoints" can change. This will result in different length of columns or rows. Move this terminal outside of the loops.

Transposing the array in "write to spreadsheet file" is not good. the VI uses the Transpose function which will allocate the memory again and then
move the data. You can do this easier by changing the terminal which is connected to the N terminal of the for loops by using the select function.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 4 of 6
(9,547 Views)
Hi Waldemar!

> Create a For loop. Create a shift register and connect the array to
> the shift register. Connect one of the numeric controls to the N.

The problem begins exactly at this point. By the way, I use Labview 6.0 You
cannot connect a control to the loop-maximum N. Please try it. Or is there
something I am doing wrong?
Thank you,
Oliver.
0 Kudos
Message 5 of 6
(9,547 Views)
> The problem begins exactly at this point. By the way, I use Labview 6.0
You
> cannot connect a control to the loop-maximum N. Please try it. Or is there
> something I am doing wrong?
> Thank you,
> Oliver.

I am sorry. I was too stupid to do it. Now I get it!! And it works!! Thank
you very much!!
Best regards,
Oliver.
0 Kudos
Message 6 of 6
(9,547 Views)