10-15-2013 10:02 AM
When size of array A = 1; then i = 0 and so I subtractnothing to get the last element
When size of array A = 2, then when i =0 i have to subtract 1 and when i = 1 i have to subtract 2
When size of array A = 3, then when i = 0 i have to subtact 1, when i = 1 subtact 2 and when i = 2, subtract 3... and so on
The goal is actually:
to replace the last element, when Array size of A = 1
to replace the last element and second last emelent one after teh other , when Array size of A = 2
to replace the last element , second last emelent and third last element one after teh other , when Array size of A = 3
.
and so on
In this VI i am able to replace only one element. i.e output shows only the last action done.
Also I dont want to use case structures for every situation because the array size may vary.
I want to have a general way to automatically generate the above mentioned operation depending on the arrays ize .
10-15-2013 10:12 AM
Are you always going to replace the data with constants, or where will you get the replacement strings from?
Cameron
10-15-2013 10:14 AM
You are not understanding dataflow. With every iteration of the loop, you are acting on the same initialized array stored in the input tunnel. If you want to keep the modified array for the next iteration, you need to keep it in a shift register.
10-15-2013 10:16 AM - edited 10-15-2013 10:21 AM
For the ease of posting i set it as constant. Actually the replcacement values are obtained from another sub vi. i.e if the Array size = 1, there will be only one replacement value. If array size = 2 then there will be two replacement values and these are to be replaced sequentially according to the FOR Loop run
@ Altenbach: I know using shift Registers. But then I need to do something to follow up according to Array size and cvase stucture , right?
10-15-2013 10:19 AM - edited 10-15-2013 10:20 AM
i think 'delete(last element) from array' will do what you need?
10-15-2013 10:20 AM
You could do it a lot simpler with Replace Array Subset (once you convert your replacement data into an array) and then you wouldn't need the FOR loop at all.
What difference does it make when the data is replaced in the array, as long as it gets to the right place?
Cameron
10-15-2013 10:21 AM
@Nghtcrwlr wrote:
When size of array A = 1; then i = 0 and so I subtractnothing to get the last element
When size of array A = 2, then when i =0 i have to subtract 1 and when i = 1 i have to subtract 2
When size of array A = 3, then when i = 0 i have to subtact 1, when i = 1 subtact 2 and when i = 2, subtract 3... and so on.
You are really not making a lot of sense.
There is no array labeled "A" anywhere on your diagram.
@Nghtcrwlr wrote:
The goal is actually:
to replace the last element, when Array size of A = 1
to replace the last element and second last emelent one after teh other , when Array size of A = 2
to replace the last element , second last emelent and third last element one after teh other , when Array size of A = 3
.
and so on .
Isn't this equivalent to just create a new array of the same size containing the new value in all elements?
What is the meaning of "one after the other"? What determines the order and why is it important. It seems that only the final result really matters.
10-15-2013 10:41 AM - edited 10-15-2013 10:45 AM
Ok.. sorry for the complications. Array A is actually the replacement elements. If Array A has three elements, then last three elements of the Input Array have to be replaced by these. If 4, then last 4 lements. and so on...
"What is the meaning of "one after the other"? What determines the order and why is it important. It seems that only the final result really matters."
For each time the outer loop runs, a mysql command is executed. i.e the final result have to be also saved in mysql.
10-15-2013 10:54 AM
You're making it unnecessarily complicated (and, as altenbach says, it won't work). Just take your replacement array and use Replace Array Subset to stick it into your original array with an offset of 1 element. All done.
Cameron
10-15-2013 11:02 AM
@Nghtcrwlr wrote:
Ok.. sorry for the complications. Array A is actually the replacement elements. If Array A has three elements, then last three elements of the Input Array have to be replaced by these. If 4, then last 4 lements. and so on...
Again, isn't that statement equivalent to replacing ALL array elements? Again, what is "these"?
Nghtcrwlr wrote:"What is the meaning of "one after the other"? What determines the order and why is it important. It seems that only the final result really matters."
For each time the outer loop runs, a mysql command is executed. i.e the final result have to be also saved in mysql.
You are not answering my question. I don't care where it goes afterwards. Do you want to replace all N elements at once, or one at a time until all are replaced? Do intermediary results also need to go to the database or only after all elements have been replaced? Should they be replaced in ascening or descending index order? If only the final result matters, the actual order of replacement seems irrelevant to me.
Overall, the code you are showing seems confusing. What are the actual inputs? For example is the string diagram constant actually something that changes with every iteration of the outer loop in your real program? Currently, the string parsing needs to be done only once and it would belong outside the outer loop.