03-17-2011 01:18 PM
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.
Solved! Go to Solution.
03-17-2011 01:52 PM
Hi twolfe,
there is no need on multiplying an array with an other array with constant values. You can just multiply with a constant.
03-17-2011 02:04 PM
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
03-17-2011 02:20 PM
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.
03-17-2011 02:24 PM
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
03-17-2011 02:26 PM - edited 03-17-2011 02:26 PM
btw, it can be done with a 1D-array as well 😉
03-17-2011 02:45 PM
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.