05-20-2013 05:08 PM - edited 05-20-2013 05:09 PM
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!
05-20-2013 06:11 PM - edited 05-20-2013 06:14 PM
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.
05-20-2013 07:59 PM
@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". 😉
05-20-2013 08:00 PM
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.
05-20-2013 08:16 PM - edited 05-20-2013 08:18 PM
@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 .
05-20-2013 10:15 PM
Since the lowest index is zero and we cannot have negative array indices, the only direction an array can grow is up. 😄
05-20-2013 10:34 PM - edited 05-20-2013 10:35 PM
A few comments about your code:
The simplest way to create and display an array with element 0..4 would be as follows.
05-21-2013 12:00 AM - edited 05-21-2013 12:00 AM
@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.
05-21-2013 02:17 AM
@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
05-21-2013 02:47 AM
There is no gravity on the front panel or diagram, so the only "up" can be defined in the direction of growing indices. 😄