07-20-2010 03:42 AM
I'm using Labview 2009 and i have a proble with arrays....i have to implement in Labview the following code (X and Y are the numeric input arrays):
for( i=0 to MAX(X)) {
if ( X[i]> ( X[i-1] +1 ) ) {
X.add( X[i], X[i-1]+1) // add the value X[i-1]+1 in the X[i] position of the X array
Y[i]=0
}
else
Y[i]=Y[i]
}
if i try to add elements in the original Y array with the "Replace array subset" funcion, the output array is not modified by the VI. If i try to initialize and build a new array, i obtain an array of zeros. Can someone help me?
Solved! Go to Solution.
07-20-2010 04:22 AM
Hey Topone,
I have created a snippet which is attached to this thread. I have used several functions in my code that are the LV equivalent to those you would use in C. I have made some comments in the code to help you navigate through the functions, you can also use the highlight execution tool to determine exactly how the code works. If there is anything you don't quite understand including importing code snippets please don't hesitate to ask.
07-20-2010 04:32 AM
Hey Topone,
Also I would just like to add, you can find loads of examples on code implementation if you click on the "help" in the tool bar, and go to "find examples". Also there are LV tutorials on our website: http://www.ni.com/gettingstarted/labviewbasics/
07-20-2010 07:49 AM
Hi Andy, thanks for your reply...maybe i have not explained well...i have 2 arrays on input, for istance:
X = [ 0 1 12 22 24 ]
Y= [ -4 1 -16 -2 1]
the code that i've posted return on output (and this is what i need) :
X = [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ]
Y= [ -4 1 0 0 0 0 0 0 0 0 0 0 -16 0 0 0 0 0 0 0 0 0 -2 0 1]
The VI that i've built from your image ( and those i've tried before) return the following result:
Y = [ -4 1 0 0 0]
what's wrong?
07-20-2010 09:13 AM
If you just want to add 0's to the indexes that doesn't exist in X[] then try this.
07-20-2010 09:27 AM
If you want exactly what you posted then try this