LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replacing elements

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  .

 

 

Replace.png

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 16
(3,114 Views)

Are you always going to replace the data with constants, or where will you get the replacement strings from?

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 2 of 16
(3,106 Views)

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.

0 Kudos
Message 3 of 16
(3,101 Views)

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?

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 16
(3,095 Views)

i think 'delete(last element) from array' will do what you need?

0 Kudos
Message 5 of 16
(3,091 Views)

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

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 6 of 16
(3,089 Views)

@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.

0 Kudos
Message 7 of 16
(3,086 Views)

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.

 

 

Replace_1.png

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 8 of 16
(3,070 Views)

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.

 

original.png

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 9 of 16
(3,062 Views)

@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. 

0 Kudos
Message 10 of 16
(3,061 Views)