LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

1D array output

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 

0 Kudos
Message 1 of 5
(6,650 Views)
Here is an example block diagram of what I am trying to do, only the last value (value from last iteration) is correct, all the other values gets overwritten with zeros.
0 Kudos
Message 2 of 5
(6,646 Views)

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???

 

 

Message Edited by altenbach on 03-22-2009 11:27 PM
0 Kudos
Message 3 of 5
(6,641 Views)
The problem is that what I am trying to do is not that simple, I just created this as an example. What I need to do is store the information extracted from an image (one new image on every iteration) in array form with each index corresponding with the image processesed (image 0 is not processed to prevent indexing issues). Now depending on the information extracted from the image I need to do x else y. Where x will be to do some calculations and y will be to store the previous values (at previous index). But this is impossible if the previous value is overwritten with 0 everytime. I can build the array without problems outside the mathscript node by using "build array" however I need a way to do it inside the mathscript node. is there any way to make this happen or should I try finding an alternate solution. Thanks
0 Kudos
Message 4 of 5
(6,633 Views)

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.

 

Message Edited by altenbach on 03-23-2009 09:00 AM
0 Kudos
Message 5 of 5
(6,613 Views)