LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Indexing arrays there has to be a better way

I have a 1D array of 25 elements, that could grow at a later date...

 

I heed to write each element to a local variable.

 

What is the best way besides using the Index Array with 25 index inputs and outputs?

 

Why dosen't Decimate 1D Array have an option to function this way?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 1 of 9
(3,736 Views)

You can build an array of references to each of the local variables and use a for loop to read the array values and write them to their value property.

 

write array to local vars.png

Brian Smith
Advanced Light Source
Lawrence Berkeley National Laboratory
0 Kudos
Message 2 of 9
(3,717 Views)

RTSLVU wrote:

I have a 1D array of 25 elements, that could grow at a later date...

 

I heed to write each element to a local variable.

 

What is the best way besides using the Index Array with 25 index inputs and outputs?


Does this mean you have 25 local variables??? And if the array later grows, you want to add more locals???

 

Why don't you make the control or indicator an array instead??

 

Can you show us some code so we get a better feeling on what you are trying to do?

 

(also, if you want all 25 element is sequential order, you don't need to wire any indices. SImply resize for 25 output (see here) ;))

Message Edited by altenbach on 07-16-2009 12:17 PM
0 Kudos
Message 3 of 9
(3,711 Views)

RTSLVU wrote: 

I heed to write each element to a local variable.


Red flag.

 

Please elaborate on exactly what you're doing. This is usually a bad idea. 

 

EDIT: I see altenbach already covered this. Got distracted while writing reply.

Message Edited by smercurio_fc on 07-16-2009 02:18 PM
0 Kudos
Message 4 of 9
(3,704 Views)

I'd preface this by saying that there is usually a more elegant solution than using 25+ local variables for anything.  If I were to do this, I'd use the 'Invoke Node' to Set a control value for each element of the array.  I have included a simple example, in this case the names of the controls are sequentially numbered so it is easy to generate the names, otherwise I suppose you could create a constant array of strings to match the name to the proper array index.  It still is not a pretty solution, but it does look better than 25+ outputs on the index array vi going to 25 local variables.

 

 

Message 5 of 9
(3,697 Views)

Is 25 locals too many? My entire project probablyhas around 150 locals. In short I have to control and monitor 5 systems under test. 250 measurment points of temperature, AC/DC voltage, and AC/DC curent, and 25 control points, plus this is located outdoors so I also have to monitor the equipment cabnet.

 

Anyway here is a small vi I was experementing with. In a nutshell I need to save a nd restore bunch timers in case the computer gets rebooted, crashes, or whatever...

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 9
(3,691 Views)

btw, both of your FOR loops can be deleted without change in outcome. The conversion bullets accept array directly. Try it! 😉

 

 

So, why do you need locals? You code does not explain....

 

Why not keep the times in a shift register as an array?

 

 

0 Kudos
Message 7 of 9
(3,678 Views)

altenbach wrote:

btw, both of your FOR loops can be deleted without change in outcome. The conversion bullets accept array directly. Try it! 😉

 


Smiley Surprised OMG, I never would have suspected.

 


altenbach wrote:

So, why do you need locals? You code does not explain....

 

Why not keep the times in a shift register as an array?

 

 


As stupid as it sounds, the person that approves my code does not like shift registers.Smiley Sad

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 9
(3,666 Views)
 
RTSLVU wrote:

As stupid as it sounds, the person that approves my code does not like shift registers.Smiley Sad

 


It doesn't just SOUND stupid. It's D-U-M dumb.  Smiley Sad

PaulG.
Retired
Message 9 of 9
(3,660 Views)