LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build an array on element at a time

I have grabbed data from file and have used decimate 1 D array to pull out the elements I needed and have calculated a value in a while loop as I am indexing through the incoming data. Now I need to form an output array of the calculated values. In C this is easy. You just assign a value to the element in the new array. Can not seem to be able to figure this out.

0 Kudos
Message 1 of 8
(2,825 Views)

It's easier in LabVIEW. Instead of a while loop, wire the array into a for loop. Do the calculation inside the loop and pass the value out. Auto-indexing will create your output array. No indexing required at all.

 

 

Have you taken the time to take the LabVIEW 101 tutorial? If not, it would be highly advised to do so.

0 Kudos
Message 2 of 8
(2,817 Views)

It looked simple but when I tried it all of the arrays lost a dimension going in and gained a dimension leaving. What gives?

0 Kudos
Message 3 of 8
(2,800 Views)

 


@ITElearner wrote:

It looked simple but when I tried it all of the arrays lost a dimension going in and gained a dimension leaving. What gives?


The arrays are indexed going into and out of a loop structure.  That is the normal and expected behavior.  You can disable indexing by right-clicking on the tunnels if you want to handle the indexing manually.

 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 4 of 8
(2,780 Views)

Hi ITE,

 

"the arrays lost a dimension going in and gained a dimension leaving"

That's the concept of auto-indexing! You feed a 1D-array to the loop, in the loop you process the single items and after the loop you get your processed array back...

You said you want to calc on the single elements...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(2,778 Views)

If you're doing the same calculation on every element you likely won't need the loop at all.

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 6 of 8
(2,766 Views)

I have used a while loop because of what calcultions I was doing. The concept I had to learn was setting the tunnels to shift register.(not very intuitive) I can see the use of the for loop for some other applications and will try to remember the advantages.

 

Thanks for the feedback.

0 Kudos
Message 7 of 8
(2,736 Views)

@ITElearner wrote:

 The concept I had to learn was setting the tunnels to shift register.(not very intuitive)


That's where the tutorials and LabVIEW basics courses come in handy.  To learn the things that you wouldn't have thought of otherwise.

 


LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

Message 8 of 8
(2,731 Views)