From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding to arrays by corresponding elements

Solved!
Go to solution

Hi guys,

 

Is there any way to combine two 2D arrays to get new one with corresponding elements added?
I mean like matrix addition in mathematics:

pavyzdys_masyvai.jpg







Thanks!

0 Kudos
Message 1 of 8
(4,237 Views)
Solution
Accepted by topic author mazhius

Just Add them!

Add Array.png

0 Kudos
Message 2 of 8
(4,229 Views)

Add should work.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 8
(4,228 Views)

It worked, funny. Did not think about simply adding them. But there is another idea, which would maybe make addition unnecessary:

If let's say I have 2 for loops, one is inside of the other. And I initialize an array full of zeroes outside both of them. Then, first(outer loop) fills some spaces in my array with values, after that the second loop(inner loop) fills some other spaces with values-in the end after both loops have finished, wouldn't my values end up in one array if my "Replace Array subset" functions are connected with shift registers?

0 Kudos
Message 4 of 8
(4,217 Views)

mazhius wrote:If let's say I have 2 for loops, one is inside of the other. And I initialize an array full of zeroes outside both of them. Then, first(outer loop) fills some spaces in my array with values, after that the second loop(inner loop) fills some other spaces with values-in the end after both loops have finished, wouldn't my values end up in one array if my "Replace Array subset" functions are connected with shift registers?

What is your goal with this logic?  This does not sound like a simple "Adding".


GCentral
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 Kudos
Message 5 of 8
(4,189 Views)

What is it you really want to do? Create a 2D/Matrix of random numbers? This is a simple way.

Create 2d array of randoms.png/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(4,184 Views)

OR, an alternative interpretation of your question: If you have 2 nested loops with (the normal) autoindexing outputs, you'll get a 2D array as output. With Replace array you'll a part of your array with this "chunk" of 2D data.

If you r-click the loops output you can change to concatenating and/or conditional to get it as 1D array, in which case you'll replace 1 row or column.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 8
(4,182 Views)

Well my goal was to write a program(it's pretty much the first time for me working with labview) which would move my detector using two controllers along X and Y axes and scan the the whole area. Let's say if my area is 3x3 sized, then outer loop(green arrow) moves my detector along X axis, scans a value and writes it to an array. Then other two points in the same column would be scanned by inner loop(blue arrow) and saved into another array and added to the first one later, OR would be saved into the same array using shift registers. That was an idea.failed scan.jpg

Anyway, for now I decided to stick with a slower scan a column>back to start>scan another column algorithm, because first one takes more time for now and right now it's still worth to use slower algorithm to do the work. Thanks!

0 Kudos
Message 8 of 8
(4,130 Views)