11-06-2014 05:47 AM
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
Solved! Go to Solution.
11-06-2014 05:55 AM
11-06-2014 11:10 AM
@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.
11-06-2014 02:04 PM
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.
11-06-2014 11:46 PM - edited 11-06-2014 11:49 PM
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