03-22-2009 09:51 PM
I am creating a 1D array inside a mathscript window, however there is some issue with the indexing. I am updating the array in the following manner
array(loop_iteration,1) = value;
The problem is that the array is growing dynamically, but only the last value gets saved while the previous values gets replaced with zeros. Am i doing something wrong?
Thanks
03-23-2009 01:03 AM
03-23-2009 01:26 AM - edited 03-23-2009 01:27 AM
Your problem is the FOR loop and how you coded outside the mathscript node. You have some serious misconceptions about the dataflow. At each iteration of the FOR loop, you create a new array, overwriting the array of the previous iteration. You can easily see what's happening by autoindexing as shown in the picture.
Of course there are probably easier ways to do all this without mathscript. 😉 (e.g. an array in a shift register)
What exactly are you trying to do???
03-23-2009 07:50 AM
03-23-2009 11:00 AM - edited 03-23-2009 11:00 AM
In any case, your code has obvious mistakes. For example you define two indices, but only define the output as 1D array. That is incosistent. It you work on a 1D array, you should only have one index.
To make your code work, you would need to keep the array in a shift register, e.g. as follows.
I really don't recommend this because of performance problems, If possible, you should do these operations "in place". Can you tell us a bit more about your application? Most likely, a plain LabVIEW version without mathscript would be simpler and faster.