LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create an n-dimensional constant array?

Solved!
Go to solution

I have a code where I am trying to mathematically manipulate arrays in a while loop. I was planning on multiplying an array by a constant, but on the second iteration the constant actually ends up changing to an array of different constants*. Therefore, I'd like to define an array of constants of one value. I did this using the "array constant". I stuck a double point constant inside and wired it to me terminal. One problem I'm having is that the size of the array isn't matching my other array. In the box to the left of my double point constant value, I put in "10" because the size of the array I want is 10. Instead of generating a 10 element array with all the same constant, it generated...uhhh...nothing. I received null: []. What am I doing wrong?

 

Next, is there a way to define the length of this array based on the length of another array? For example, the array I want to work with is 10 elements, but it might not ALWAYS be 10 elements. I'd like to put in some flexibility so that if it changes to 30 elements, the constant array I create will be smart enough to know it also needs to be a 30 element array.

 

Also, I apologize for not including a picture. The computer with LabVIEW is not the same as the computer connected to the internet. Furthering my frustration, the only way I can transfer data from that computer to this one results in encrypted data unless I burn a CD. Ohhhh working for the federal government is a delight sometimes.

 

*The constant changes to an array of constants because the process is iterative. I start with a guess for the constant, but then that guess gets updated by the values in the array, forcing it to become an array itself.

0 Kudos
Message 1 of 7
(8,290 Views)

Hi twolfe,

 

there is no need on multiplying an array with an other array with constant values.  You can just multiply with a constant.

 

Array.png

 

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 2 of 7
(8,282 Views)
Solution
Accepted by twolfe13

And if you really want to keep using the arrays, yes indeed there is a way to make the lenght of you array the same as the length of another array.

 

Here's an example with an 2D-array :

- Array in is the original array

- 10 is the constant which acts as the multiplier

 

Multiple.png

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 3 of 7
(8,278 Views)

The problem is that when I do a shift register in my while loop, the constant is changed to an array. So to make the loop work, I want to initialize the loop with an array of constants.

 

This is a simplified version of what I'm trying to do in pseudocode:

 

C_old = [0.99, 0.99, 0.99]  // I shortened this to a 3 element array for simplicity

C_new = [0.99, 0.99, 0.99]

Re_old = [1E5, 1.2E5, 1.5E5]

 

while (abs(C_old-C_new) < 0.001)

{

     Re_new = Re_old*(C_new/C_old)

     C_newer = a bunch of stuff as a function of Re_new

     C_old = C_new

     C_new = C_newer

     Re_old = Re_new

}

 

So in my while loop, I have C_old, C_new, and Re_old on the boundary as shift registers. I don't really need the constants to be arrays, but the problem is that when I do C_newer as a function of Re_new (which is an array), I get an array of constants. So to make the shift registers work, they need to be the same datatype, so I need to initialize an array of constants at the beginning as C_old and C_new and also to test the values to stop the while loop.

    

0 Kudos
Message 4 of 7
(8,274 Views)

Can you post your VI in here?  Because I'm not getting the idea of a constant becomming a array when you put it into a shift register.

Have you looked at the second post?  This is the one where I showed you how to create a constant array on the fly with the dimensions of an other array

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 5 of 7
(8,268 Views)

btw, it can be done with a 1D-array as well 😉

Array.png

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 6 of 7
(8,267 Views)

Thanks, that helped me get to the right answer I think. I got the constant array to work. I ended up with an infinite loop, but I think that's my own problem, haha.

0 Kudos
Message 7 of 7
(8,257 Views)