06-27-2012 12:56 PM
Hi,
I'm having trouble populating a 1D array using a Replace Array Subset function. The two arrays coming from the top are two separate ones.
This program is supposed to compare two adjacent elements in one array and flows through a case structure. If true then it outputs an index integer if not then right now it outputs the default (don't know how to make it output nothing or skip). But using the output index, it indexes from another array to receive another corresponding element. I want to populate a new array with these elements which pass the decision process on the left. I think I'm supposed to use Replace Array Subset function but I don't know how to set the index for that function so it increments after each new element is put in.
I initialized an array with 1000 spots but since I did that I couldn't really use append array.
If there is another function I'm supposed to use or perhaps a totally easier approach to do this then ideas are welcome. I'm also trying to populate a text file with these elements but I don't know if that's going to work out either.
Thanks!
06-27-2012 01:07 PM
@Ghoster wrote:
Hi,
I'm having trouble populating a 1D array using a Replace Array Subset function. The two arrays coming from the top are two separate ones.
This program is supposed to compare two adjacent elements in one array and flows through a case structure. If true then it outputs an index integer if not then right now it outputs the default (don't know how to make it output nothing or skip).
What does the text in bold mean?
06-27-2012 01:22 PM
On the wall of the outer case structure, the blue box has a white inside with a blue dot in the centre because I checked "Use default if unwired". I just left the 'false' side empty.
06-27-2012 01:30 PM - edited 06-27-2012 01:33 PM
You need to use a shift register to keep your array current. You are basically reinitializing and overwriting with each loop due to just using terminals. I'm also noticing you are not telling which index to replace. I think it defaults to the first element if unwired. So you are only replacing the first element.
06-27-2012 01:38 PM
@Ghoster wrote:
On the wall of the outer case structure, the blue box has a white inside with a blue dot in the centre because I checked "Use default if unwired". I just left the 'false' side empty.
I am not quit understanding what you are trying to achieve.
Comment: Since you are comparing DBL, checking for inequality is unnecessary.
Based on the PNG image, you want to populate a second array with elements from the first array in which the value of that nth element is greater than the value of the (n-1)th element.
When you the Use default if unwired, that index value will be 0 so you will be adding the 0th element of the first array to the second array.
Is the above what you really want to happen?
06-27-2012 02:05 PM
Hey crossrulz,
Where would I use shift registers in this case?
Yes, I didn't tell it which index to replace becasue I wanted it to step through the output array to populate the whole array. I probably need some counter but I got stuck with that and left it blank.
06-27-2012 02:11 PM
Hey nyc,
Sorry for being so vauge with my question. I don't really know why checking for inequality is unnecessary for dbl.
But no, that's not what I want. I want it to step each index of the new array and populate it with values based on the logic in the case structure. (not just the 0th element).
06-27-2012 02:14 PM
@Ghoster wrote:
I want it to step each index of the new array and populate it with values based on the logic in the case structure. (not just the 0th element).
And I still don't know what that logic is, because you haven't written it here.
06-27-2012 02:26 PM
There's 3 arrays.
From array 1, I compare element i and element i+1. If they are not equal then I compare equality. Else I want to do nothing.
In the equality, if element i is less than element i+1 then I want to output the index i+1 else I want to output index i. This outputted index will be used to index array number 2 to get a new element. I want to use these new elements from the indices and corresponding elements from array number 2 to populate the new array (number 3).
Sorry, I hope this clarifies things.
06-27-2012 02:31 PM - edited 06-27-2012 02:33 PM
@Ghoster wrote:
I don't really know why checking for inequality is unnecessary for dbl.
There are many discussions about hwo equality checks are invalid for floating point numbers due to rounding somewhere in the binary code. Every computer language has this issue.
@Ghoster wrote:
But no, that's not what I want. I want it to step each index of the new array and populate it with values based on the logic in the case structure. (not just the 0th element).
How large is your initial array? If it is less than 1000 elements, then your results make perfect sense.
Anyways, here's an example of what I was saying with the shift registers.