05-20-2021 11:42 AM
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!
Solved! Go to Solution.
05-20-2021 11:46 AM
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.
05-20-2021 12:07 PM
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).
05-20-2021 01:50 PM
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.
05-20-2021 02:58 PM
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!