LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace array subset

Solved!
Go to solution

I have a 2D array (nx1002) and a 1D array(1000).

 

It need to insert the 1D array into the 2D array at position of row X, colume 2.

This operation will keep running all the time, repeating with index X changing. Volume data may coming in.

 

Since 'insert into array' cost memory and not fit to use here, I tried to use 'replace array subset'.

 

But in 'replace array subset', cannot set one input as 2D array, another input as 1D array. Also I dont want to loop for 1000 time.

 

One way I think of is using the 'change dimension of the array' to change the 1D array into a 2D array, then can using the 'replace array subset'.

 

I am not sure if this is the correct way, or there are other nornal and good ways to do it. Thanks a lot. 

 

0 Kudos
Message 1 of 13
(6,051 Views)
Solution
Accepted by alex.

I have no issues overwriting part of a 2D array with a 1D array:

 

Ton

 

 

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 2 of 13
(6,043 Views)

Thanks, got it.

 

That means it can only replace one entire row, cannot replace part of the row.

 

Not sure if I am right.

 

 

0 Kudos
Message 3 of 13
(5,997 Views)

You can replace part of a row.  You need to wire to both the row and column inputs to specify where the replacement will start.  If the replacement is too large, the sub array is cropped to fit.  See the detailed help file for Replace Array Subset for more details.  Also it is often useful to wire a little test VI to try different things.

 

Lt=ynn

Message 4 of 13
(5,986 Views)

If I wire both row and column input, the input sub array must be 2D, cannot be 1D. If my data is 1D, it need to do a convert and take time cost.

0 Kudos
Message 5 of 13
(5,968 Views)

Hi Alex,

 

how much time does it cost to insert a small BuildArray to convert from 1D to 2D?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 13
(5,959 Views)

The time cost to do a Reshape array to a 2D array is small, else you'll have to solve it slightly different.

- Extract row X through Index Array from 2D array

- Replace array subset in 1D extract (since you didn't want to change the full row)

- Replace row X in 2D array.

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 13
(5,957 Views)

Hello,

following this topic, I propose to consider a 2D array and the replacement of a column by a new column. 

The new column might have more or less elements that the old one. All unnecessary element will be filled by zeros. 

For example, a 2D array of 3 columns has (let's say) 10 elements in column 0 (C0), 20 elements in C1, 5 elements in C2. So here, the size array will output 20. If I want to replace C2 by a new C2 of 3 elements, starting from row 0, then the other 16 elements from row 4 to 20 will be filled with zeros in the column C2. All other columns will not be modified. 

So I build up a vi that intends to do it. 

It seems to work, but there is a bug when the selected column is 0 or 1. I cannot understand why. 

Can someone help me to understand ? 

 

 

0 Kudos
Message 8 of 13
(4,380 Views)

Hi arienai,

 

It seems to work, but there is a bug when the selected column is 0 or 1. I cannot understand why. Can someone help me to understand ?

Why do you do all this so complicated?

Strip down to this:

check.png

(You still should check for valid column index and length of the replacement column!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(4,377 Views)

thank you very much GerdW, 

yes you are right, your code is efficient. 

My code was indeed more complex but it was for understanding my error. After looking to your code, I found that I used 2 times the insert to array, and the last one was creating unwanted output array. 

Once again, I thank you very much for your valuable help, 

Yours

0 Kudos
Message 10 of 13
(4,369 Views)