LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need multiple variables in single for loop

Hi,
 
I have a for loop in which I create array whose size is variable depending on the condition. I want to append the value of array from each iteration into output array. The output array size is pre-fixed and is initialized outside of array. In for loop I am using Replace array subset to write values from intermediate array to output array. However, I need a variable which I can use as index to write to replace array at specific points and update it according to the number of elements written in current iteration. This way I can avoid overwritting on same array elements. In short, this is how it would look like in C#.
 
int j = 0;
for(int i=0; i<inputArraySize;i++)
switch{
case 1: outputArray[j] = inputArray[i]; j++; break;
case 2: outputArray[j] = inputArray[i]; j++; outputArray[j] = somethingElse; j++; break;
}
 
return(outputArray);
 
I dont know how to do this in Labview. Any help is appreciated.
0 Kudos
Message 1 of 7
(3,327 Views)
The way youhave it written, you need to use another shift register for the index for Output Array.  Depending on your case statement, you either add 1 or 2 to the value for the next iteration.  Initialize the shift register to 0.

As an aside, why aren't you using a shift register for Output Array?
0 Kudos
Message 2 of 7
(3,321 Views)

Thanks fo ryou rsuggestion. I will try using it.

Also, What do you mean by using shift register for output array?

0 Kudos
Message 3 of 7
(3,320 Views)
You init the array and write it to an indicator and then use local variables inside your for loop to update the array.  If you wire the output of the Array Init to a shift register on your for loop, you will update the array with every iteration, then after the for loop, wire the output shift register to your indicator.
0 Kudos
Message 4 of 7
(3,315 Views)
I tried using shift register for output array. It only takes values from the last iteration. I am confused as to how should I do it?
0 Kudos
Message 5 of 7
(3,313 Views)
I didn't see any changes in your second VI, but this is what I am talking about.  I didn't try to to clean everything up, but you should get the idea:



The true case:



The encodeLagging case:


Message Edited by Matthew Kelton on 10-17-2007 03:36 PM

Download All
0 Kudos
Message 6 of 7
(3,306 Views)
Thanks a lot for your time and help. I really appreciate it.
0 Kudos
Message 7 of 7
(3,300 Views)