LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling N dimentional array without for loop

Solved!
Go to solution

Hello,

I would like to build an N dimensional array without using for loops one inside the others N times  because I would like to have the number of dimensions variables, so I don't want to change the code  by adding or removing for loops everytime I change the number of dimensions. I would like to start let's say with 7 dimensions 10x10x10x10x10x15x20.

Thanks,

Zied

0 Kudos
Message 1 of 23
(5,663 Views)

Did you try to use the Initialize array function? 

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 23
(5,652 Views)

Yout can't.  Whatever you do programmatically has to have the same datatype on its output wire.  So you can create a 1-D array and have it pass its data down the line, then later create a 7-D array.  The 7-D array wire is a different datatype and would break all downstream code.

 

The only thing you can do is create a 7D array, and if you actually want it to be a 2D array, make the other 5 dimensions only 1 element wide.

0 Kudos
Message 3 of 23
(5,650 Views)

Hello,

You can easily fill an n dimension array using Initialize Array VI, however the number of dimensions remain non-variable. Still it is more simple and flexible, than working with loops. Donwside is, you can't create arrays based on some logic, it just fills the whole with the same element. Replacing some elements one by one can be done with the Replace Array Subset VI, but replacing all I'm afraid still requires n embedded for loops.

 

init arr.PNG

 

Regards,

Adam

0 Kudos
Message 4 of 23
(5,643 Views)

Thank you guys,

Actually, I need to fill the tables with variable number and not to just initilise it.It is doable  with few dimensions but if I need 50 or 100 dimensions then it will be very tiring and I have to change the number of dimensions each time I change the diemsion of the function I have.

Cheers.

Zied

0 Kudos
Message 5 of 23
(5,633 Views)

If you need that many dimensions, then you may want to reconsider how you structure you data.  What is the real world meaning of 50-100 dimensions?  Why is that number so variable?

 

The most number of dimensions I've ever needed was 4.  and I could possibly see expanding that to 5.  But other than this one particular project, I've only ever needed 3 or less.

0 Kudos
Message 6 of 23
(5,629 Views)

Hi,

I am trying to calculate f(x1,x2...,xn) of the Ackley function that can be of any dimensions.

http://www.sfu.ca/~ssurjano/ackley.html

I am trying to calculte xi for a grid of 10 or customisable for each dimension.

Thanks,

Zied

0 Kudos
Message 7 of 23
(5,625 Views)

I am with RavensFan, in any of the application I worked I never wanted to have more than 2 dimensions. In one case I used 3 dimensions which also ended up as 2d after restructuing the data.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 8 of 23
(5,624 Views)

I don't think your computer can handle a 50 dimension array.

 

Think about.  Suppose each dimension was 10 elements, the smallest dimension of your 7D array you gave in the original post.  A 50-D array is 10^50.  That is a heck of a lot of zeroes.  If each value in the array was only a byte, you don't have enough memory in your PC to hold it all.

 

Let's say it was only 2 elements in each dimension.  Then you are talking 2^50 bytes.  1.12 x 10^15 bytes.  .  Which is 1125 Terabtyes.

0 Kudos
Message 9 of 23
(5,599 Views)

Hi again, Maybe I will not try to use this function with 50 dimensions after your warning of memory but still need to try it with 7 to 15 dimensions.

Thanks,

Zied

0 Kudos
Message 10 of 23
(5,582 Views)