キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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 件の賞賛
メッセージ1/13
4,226件の閲覧回数

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 件の賞賛
メッセージ2/13
4,205件の閲覧回数

@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 件の賞賛
メッセージ3/13
4,185件の閲覧回数

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

 

 



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 件の賞賛
メッセージ4/13
4,185件の閲覧回数

@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 スマイリー とてもハッピー

0 件の賞賛
メッセージ5/13
4,178件の閲覧回数

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

0 件の賞賛
メッセージ6/13
4,166件の閲覧回数

 

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 件の賞賛
メッセージ7/13
4,157件の閲覧回数

@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 件の賞賛
メッセージ8/13
4,143件の閲覧回数

@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 件の賞賛
メッセージ9/13
4,131件の閲覧回数

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

0 件の賞賛
メッセージ10/13
4,121件の閲覧回数