LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop auto indexing for the longest array length

Solved!
Go to solution

I am trying to add elements from two arrays together. Is there a way to change the for loop default auto indexing's iteration number (smallest of the two array length) to the longest of the two array length? Or are there easier ways to add individual elements from arrays together?

 

Many thanks!

0 Kudos
Message 1 of 5
(1,443 Views)
Solution
Accepted by topic author AcceptablePlants

You would need to use Reshape Array to make the two arrays the same length (reshape the smaller array to match the length of the larger array).  And if you are just doing simple addition between the two arrays, the Add will accept arrays, so you shouldn't need the FOR loop.


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 2 of 5
(1,438 Views)
Solution
Accepted by topic author AcceptablePlants

When adding two arrays, the shorter size will win, FOR loop or not. What result do you expect for the extra elements? Do you wan to assume a value of zero for the missing values? (when multiplying, you might want to assume a value of 1, depending on the problem).

 

Exactly why do you even have this problem? Do you always know which array is longer?

 

Here are two possible solutions, but there are many more. (assuming you don't know anything about the length of each).

 

 

altenbach_1-1621530275452.png

 

 

Message 3 of 5
(1,407 Views)

Thanks for the details! I am trying to change someone else's program. In their while loop, it outputs an array with 0 length initially and then changes into a constant length. 

0 Kudos
Message 4 of 5
(1,380 Views)

I assume this array is in a shift register. In this case, there are probably much better solutions, especially if the final size is known. Please show us some code!

0 Kudos
Message 5 of 5
(1,366 Views)