LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

insert number in an array

I would like to insert number in 2D array. My number should appear at 9 col. Insert functions is inserting the number but also inserts 0 in the preceedding row whenever there is a new row. My row pushes to new position and there appears new data in the first row. So it's stack (FILO). I get 8 numbers from 2D array then if it's 9th row then I get 9zeros in that row and then my 9th number. While when that 9th row was first row, the number appears on the 9th col.
I don't know how the 0s are coming in my array. Also I have to convert my number to 1D array, becasue insert array function is not accepting number if I try to place it on the 9th column.
0 Kudos
Message 1 of 6
(3,739 Views)
If you want to insert a single number into the array then you need to specify not only the column but also which row...The reason why you have to convert it to a 1D array and get all the zeroes is that if insert into array only gets to know what column it is to insert into then it expects the input data to be the array that will fill the whole column...Now if there is already two rows in the 2D array and you insert a 1 row array into the column it will fill the rest of the rows with zeroes because all columns must have the same number of rows..

Mads
0 Kudos
Message 2 of 6
(3,739 Views)
Are you sure you don't want to use Replace instead of Insert?
Replace will modify one cell. Insert introduces a new row or column.

Greg McKaskle
0 Kudos
Message 3 of 6
(3,739 Views)
I confused insert and replace in my answer...I assumed too that he would want to use replace. Inserting is ineffective as it will resize the whole array every time you do it...it's better to initialize the array to it's full size and then replace elements as they are available. If you want to know how much of the array has really been filled with valid data track the current "insert" position (like you would do if it were a circular buffer e.g.).
0 Kudos
Message 4 of 6
(3,739 Views)
I used replaced too, but at the input of replaced array, it is asking for the same data type too, as was in insert array function. So I have to first use built array function and translate my one element (SGL) to 1-D array and then I'm able to use insert or replace funcitons. So still my second part of the question is, do we need to convert an element to 1D array and then we are able to insert in an array, or we can insert and element without converting into an array?
0 Kudos
Message 5 of 6
(3,739 Views)
If you just want to replace/insert a single element then wire both the column and the row index of the cell where you want it...then the data input type will not be an array but a single value.
0 Kudos
Message 6 of 6
(3,739 Views)