LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nice way to add up big matrices in a for loop

Solved!
Go to solution

Dear Community,

 

I would like to add up big matrices consisting of measurement data. To do this, I do the measurement in a loop and then always add up the results using a shift register.

 

My problem is that if I don't initialize a zero matrix (of the same size as the measurement data) as an input for the FOR loop, the resulting matrix (after the ADD function) is an empty matrix! (See attachment "problem")

 

To solve this, I tried a workaround (see second attatchment) where I distinguish between the first measurement (which is directly sent to the shift register), and the other measurements (which are added up).

 

This workaround seems very ugly and wrong. Is there a nice way to do this?

 

Thanks ahead for your help,

Cheers

Alex

Download All
0 Kudos
Message 1 of 5
(3,080 Views)
Solution
Accepted by poeppi

Hi poeppi,

 

either you initializethe shift register with an ARRAY (a MATRIX is something different!) of the correct size OR you keep your existing solution…

Best regards,
GerdW


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

@poeppi wrote:

This workaround seems very ugly and wrong. Is there a nice way to do this?


There is nothing wrong with your solution. You can make it slightly less ugly by wiring [i] directoy to the case structure and make one case 0 and the other the default. Same difference, less code!

 

 

Still, intializing the shift regsiter with a zeroed array of the correct size is probably preferable.

Message 3 of 5
(3,015 Views)

Hi, you did the correct thing except you need to initialize the matrix outside of the for loop and have it connected to the shift register.  That way you don't need to have more than case.  Good luck. 

0 Kudos
Message 4 of 5
(2,987 Views)

Dear all,

 

Thank you very much for your answers! It's nice to know that this is actually the way it's meant to be done. It's difficult to initialize the array beforehand, as the size of the measurement data is not always the same. And thank you GerdW, I meant a 2D array of course and not matrices. As a lazy Matlab user I keep confounding them.

 

Cheers

Alex

0 Kudos
Message 5 of 5
(2,943 Views)