LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem of array manipulation

Solved!
Go to solution

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?

0 Kudos
Message 1 of 6
(3,323 Views)

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. 

Regards

Andrew George @ NI UK
Message 2 of 6
(3,310 Views)

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/

Regards

Andrew George @ NI UK
Message 3 of 6
(3,301 Views)

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?

0 Kudos
Message 4 of 6
(3,276 Views)
Solution
Accepted by topic author topone

If you just want to add 0's to the indexes that doesn't exist in X[] then try this.

Rodrigo Cuenca
www.cidesi.com

0 Kudos
Message 5 of 6
(3,255 Views)

If you want exactly what you posted then try this

Rodrigo Cuenca
www.cidesi.com

0 Kudos
Message 6 of 6
(3,246 Views)