LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into array and view output

Hello, I would like to set up an array, insert data, and view the indexed contents. I set up a small vi but there appears to be an error. This is mainly to learn Labview and then develop a larger application. Can anyone help in reviewing and commenting on this vi? Thanks Ken
 
 
0 Kudos
Message 1 of 12
(4,226 Views)
Hello Ken,

The "Run" arrow broken indicates presence of an error. If click on it, Labview explains the error.

If you do that, it say that the "insert into array.vi" has bad wired connections. And this happens because you don't have the position conected.

I've attached the corrected vi. You can only open it if you have the labview 8.2.
Software developer
www.mcm-electronics.com





PORTUGAL
Download All
Message 2 of 12
(4,212 Views)
First- you dropped down to many elements to insert.  For your example, you need only one terminal.
Second- You can only insert an element some where into the array, In your example, you initalize the array to 4 elements, so you can only insert a new element at indecies 0-4 (because you will end up with a 5 element array), remember LabVIEW is base 0, so your first index in the array is element index 0.

I hope this gets you started.  I have attached a commented updated example.  I realize someone may have responded before me, but I tried to update your example to make things easier to see.

Paul
Message 3 of 12
(4,208 Views)
You've got a control called 'Insert data at this index location' but you have it wired to one of the new element inputs of insert into array. You should have it wired to the index input. You dragged the Insert into Array down in order to create addtional new element inputs but you have nothing wired there. Just drag it up in order to remove the extra inputs. It should look something like the image below. The To DBL function is not necessary.
Message 4 of 12
(4,208 Views)
Thanks for the great responses. I am going thru them now.
0 Kudos
Message 5 of 12
(4,188 Views)
Just to be picky about the language:
 
Often people here say "insert" when they actually mean "replace". You have an array with four elements and a more typical operation would be to pick one of the elements and replace it with a new value, keeping the array at the same size! This also has significant performance advantages because the operation can be performed "in place". Here you would use "replace array subset".
 
The function "insert into array" needs to
  1. grow the array by one (most likely allocating a new copy in memory)
  2. move all elements above the insert point up by one index position.
  3. place the new element at the insert point

This is a very expensive operation and can become very confusing quickly. Because the elements change indices you get a different result depending on the order in which you insert elements.

In summary, there is a gigantic difference between replace array subset and insert into array and it is very important to know the difference. "insert into array" should be used sparingly.
 
Most likely, the correct function for your problem is "replace array subset" as in the image below:
 
 

Message Edited by altenbach on 07-10-2007 09:34 AM

Message 6 of 12
(4,174 Views)

Thanks for the comment. I tried the repalce array subset and included a loop to experiment. Where the integer goes into the the component specifying the index is an error. But it seems to me that the integer i of a for loop should be a consistent data type for an array subset index?

Thanks

Ken

0 Kudos
Message 7 of 12
(4,136 Views)
Hi Ken,

this error is due to 'auto-indexing' enabled on your for-loop output.
See attached vi on how to use 'replace array subset' inside the loop.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 12
(4,131 Views)
Any chance you can post a png? The Labview 7.1 I have will not open it. Thanks GerdW 
0 Kudos
Message 9 of 12
(4,129 Views)
Hi Ken,

well, you didn't say so before...

Message Edited by GerdW on 07-11-2007 05:07 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 12
(4,121 Views)