LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loop/Array Help

So I'm brand new to LabVIEW, and I need to use loops and arrays in a more complicated problem so I started with a simple program to make sure I know how. Turns out I don't...I was expecting the array to become [0,1,2,3,4] but nothing happens when I hit run. Screenshot is attached. The function block is "Insert into Array".

 

A few things:

Its my understanding that Arrays in LabVIEW will dynamically change size (like an ArrayList in java), but correct me if I'm wrong.

Also, I could not for the life of me figure out how to make an array with both an input and output, so thats why I created the variable (if I had to guess, thats why it doesn't work).

 

Sorry for such an elementary question, and thanks in advance for any help!

 

 

0 Kudos
Message 1 of 13
(2,953 Views)

Try using "build array" with a shift register. Insert into array confuses many a new LabVIEW programmer. That will actually insert an element into the array shifting all elements below it down. You'd want to use "replace array subset" instead of insert into array in most cases, which overwrites a value at a specific index. 

 

For this particular problem you can use autoindexing. Just wire the i terminal out of your for loop and it will create an autoindexing terminal. No array functions needed. Also, remove your local variable. Right click your wire and select create indicator instead.

 

I would suggest googling LabVIEW 3 and 6 hour tutorials. Take those and they should cover these basics.

0 Kudos
Message 2 of 13
(2,932 Views)

@for(imstuck) wrote:

That will actually insert an element into the array shifting all elements below it down.


You probably wanted to say "... shifting all elements above it up". 😉

0 Kudos
Message 3 of 13
(2,912 Views)

Greg already gave some really good advice.  I find the auto indexing tunnels will handle a large percentage of my array needs.  The next most common are the shift registers with a build array or replace array subset.  The autoindexing is usually with a FOR loop and the shift registers are usually with While loops.  If you have a more complicated problem, we can guide you a little better.

 

Oh, and here a couple of links for online tutorials that you may find helpful.

LabVIEW Basics

LabVIEW 101

 

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(2,912 Views)

@altenbach wrote:

@for(imstuck) wrote:

That will actually insert an element into the array shifting all elements below it down.


You probably wanted to say "... shifting all elements above it up". 😉


Maybe? I can't think of a single application where I've used insert into array, so I'm not sure Smiley Very Happy

0 Kudos
Message 5 of 13
(2,905 Views)

Since the lowest index is zero and we cannot have negative array indices, the only direction an array can grow is up. 😄

0 Kudos
Message 6 of 13
(2,893 Views)

 

A few comments about your code:

 

  • The array is used to show the result of an operation, thus is should be an indicator, not a control.
  • There is no need for local variables for such a simple task. Why does the array need to be an input? If you later want to add to an existing array, there are probably better ways. Do the tutorials mentioned first.
  • With each of the five iteration, the empty (?) array will get read from the input tunnel, No data is retained between operations.
  • It is not cleat how big your input arrays is. While 3 elements are visible, there is no way to tell how big it really is. From the size of the scrollbar, it looks bigger than 3 elements.

 

The simplest way to create and display an array with element 0..4 would be as follows.

 

 

0 Kudos
Message 7 of 13
(2,884 Views)

@altenbach wrote:

Since the lowest index is zero and we cannot have negative array indices, the only direction an array can grow is up. 😄


I think I was saying the same thing. When I said down, I meant physical direction. i.e. index 5 goes to 6, 6 to 7 in a vertical array on the front panel. The numerical index, is going up in terms of value. I suppose I could have said "right" also, and then what happens when the array is multiple dimentions? Ok, you win. Up.

0 Kudos
Message 8 of 13
(2,870 Views)

@altenbach wrote:

Since the lowest index is zero and we cannot have negative array indices, the only direction an array can grow is up. 😄


But all spreadsheets, constants, controls and indicators grow downwards, thus down, although the index increase. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 13
(2,858 Views)

There is no gravity on the front panel or diagram, so the only "up" can be defined in the direction of growing indices. 😄

0 Kudos
Message 10 of 13
(2,848 Views)