LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performing calculation to array element then replace back into same array

Solved!
Go to solution

I have a 2D array, c[j,i], and I want to perform calculations on each element in that array, c[j,i]=c[j,i]+d*a[i], then update that same array with the new values.  I have setup the structure using a for loop and I successfully return each new c[j,i] that I am supposed to, but I cannot seem to input those new values into the array.  I have tried using the "Replace Array Subset" node but I cannot seem to connect the output array to the same c[j,i] array.

 

Any help is greatly appreciated! 

0 Kudos
Message 1 of 9
(3,638 Views)

Hi cmersit,

 

use a FOR loop with a shift register to keep the array...

 

Attach some code to get more detailed help!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,633 Views)

 

Looking at the for loop where N=3: I need that y value that is connected to the shift register to get updated to the c1[j,i] array (using the index from the loop iterations), I cannot connect the second shift register to the array though. 

 

edit: fixed image 

Message Edited by cmersits on 11-27-2009 10:46 AM
0 Kudos
Message 3 of 9
(3,614 Views)
Don't post images in other websites. Link it directly here. Use Add Attachments located below the composer box.
0 Kudos
Message 4 of 9
(3,610 Views)

Hi cmersits,

 

you can attach pictures directly to the forum - no need for 3rd parties!

 

Well, it seems you missed the concept of dataflow, shift registers and polymorphism:

sum.PNG

 

There are free online courses at NI's website available!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 9
(3,603 Views)
This technique gives me the proper array in the 'result' array, however that does not really help me, I need that 'result' array to update the c1[j,i], this way that array gets updated each successive iteration.
0 Kudos
Message 6 of 9
(3,594 Views)
Solution
Accepted by topic author cmersits

Hi cmersit,

 

why do you need that? You did not say so before...

 

Well, create a local for c[j,i], move it into the for loop and connect it with the output of ReplaceArraySubset. It will hurt memory needs and processing speed and doesn't serve any purpose here. Replace result[] with a local of c[j,i] for this very example. Otherwise use a shift register in the outer loop!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(3,591 Views)

The reason I need to do that is because I am using sequential batch training to train a neural network.  The c[j,i] values are being updated each iteration based upon the sample 'training' data, then once every iteration is complete the 'weights' are updated (initially starting with random weights) and the overall error function is computed.  I basically keep doing that until the overall error function decreases (epoch after epoch), and I get desired weights that will give me the proper outputs when I give the network inputs.

 

I will try the local and let you know how that goes.

 

Thanks for all your help! 

0 Kudos
Message 8 of 9
(3,582 Views)
It worked beautifully!!! Thank you so much for your help GerdW!!!
0 Kudos
Message 9 of 9
(3,567 Views)