LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array problem

Hello,
I have initialised an array of a certain size (different pending on user input) to construct a Z matrix to be sent to a 3D surface graph. The array is filling with my z values in the right order(using replace array subset function), the problem is that upon recieving a new value the previous value automatically goes to zero. I finish with an array the right size but with only one value in it. Has anyone come across this problem before? I have attached the relevant vi,
Thanks
Dave
0 Kudos
Message 1 of 9
(3,379 Views)
You're code is nearly impossible to follow. You have wires going in the wrong direction, a sequence structure, and lots of local variables. I would recommend that you make subvis instead of the sequence structure. You should be able to get rid of all of the local variables by doing this as well as make your code more readable.

It's not clear to me what array you're talking about. Could you highlite the place where you're having the problem?

Also, I recommend that you post only once. There is an edit function that will allow you to go back in and edit the post (I think this works until another post has been applied).
0 Kudos
Message 2 of 9
(3,365 Views)
i'm sorry about that i should have attached a more readable vi. The problem i'm having is in sequence 2 of the structure. The local variables xy positions and resolution determine the index numbers of the array at which the A-Input value will be stored. But as i said it removes all other values,
Thanks for your time
Dave
0 Kudos
Message 3 of 9
(3,358 Views)
Hi,

I cannot be sure of what's wrong in your code, because I could not run it (there are some vi's missing).
But I am really sure that you have race conditions.
For instance, in frame 4 of that structure that's inside the for loop, you have something very strange.
The output of the for loop is connected to the terminal of the X array, but at the same time, a variable of the x array is used to do that strange thing with the array and feed new data to another variable of the x array.
When that frame is started, the x array variable is read, then the for loop is over, then it will put data in the terminal, then it will put data in the x array variable, but with the data that was there when the frame started. I know that this sounds very strange to you, but I'm sure that this kind of thing is happenning in your program.
To avoid this, don't use variables - in your program you have hundreds of them and then it is very dificult to read the code and to predict what's going to happen...
You shift registers instead, I'm sure that if you do this, your problem will be solved.
Another advice I can give you is whenever possible use replace array subset instead of insert into array. If you do this, the memory for your arrays will be allocated only once instead of in every array operation like you're doing now.

Hope this helps,
Paulo
0 Kudos
Message 4 of 9
(3,357 Views)
Hi,

Your problem is that you are changing the initialised array in every iteration of the loop and each time the initialised array is in the same situation as the first. So in the end you lost the data from all the iterations except the last one.
I changed that part of the code a little bit so it will probably work for this, but you should think about doing this operation to every variable your code has and they are a lot...

Hope this helps,
Paulo
0 Kudos
Message 5 of 9
(3,353 Views)
Hello,
Thanks for your help, the shift register allows a full row of values to be read. Im sorry but i still don't understand why the values go to zero when a new set of values are read. I thought by using the first call function when initialising the array that the array would not be re-initialised subsequently??
Thanks again for your time
0 Kudos
Message 6 of 9
(3,350 Views)
The quickest fix would be to also write to another "initialized array" local variable right after the "replace array element" node, however the code already suffers from a severe case of local variableitis. Use shift registers instead!!!
0 Kudos
Message 7 of 9
(3,342 Views)
In each iteration of the for loop, you are inserting data in a variable called initialised array (that remains the same during the complete process) and sending it to a variable called output array.
Imagine that initialised array is the following: [0,0,0,0].
In iteration 1 you want to replace element 1 by 3, so you put [0,3,0,0] in output array and initialised array remains [0,0,0,0].
In iteration 2 you want to replace element 2 by 5, so you put [0,0,5,0] in output array and initialised array remains [0,0,0,0], and so on, so in the end you will only have the values of the last iteration.
If you realy want to do things that way, replace output array by a variable to initialised array, but again, the shift registers are a much better way to do that.

Hope this helps,
Paulo
0 Kudos
Message 8 of 9
(3,340 Views)
You are missing the point. In frame 2 you never change the Initialize array. You continue to use the same input array over and over. Using a shift register will pass the data from one iteration to another. You should only read the Initialize array once and then read the value from the last iteration of the loop. This is done with an initialized shift register.

Once again, if you'll consolidate your code to get rid of all of the local variables I think that you will find it to be much easier to follow.
0 Kudos
Message 9 of 9
(3,337 Views)