LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Subtracting an elemet from an aray

I have been working on my lab view and I am facing struggle. I need to subtract the most recent element from my array from the element before it in order to find the difference between the two. Could someone help me? 

0 Kudos
Message 1 of 11
(1,467 Views)

Do you just want to operate on two elements or go over the entire array recursively?

Do you just want to calculate the derivative?

Where does the time come in (i.e. your use of "most recent"). Is the array continuously being appended?

Where does the data come from?

What should happen with the result of the difference? (just display it, build another array, etc.)

What is the datatype? (e.g. be careful with unsigned integers if the result would be negative).

 

Once you show us your code, we can give a specific answer. before that there are way too many possible scenario/solution pairs.

Easiest would be to keep the last element in a shift register (or feedback node) and compare current to previous. No array needed.

 

0 Kudos
Message 2 of 11
(1,449 Views)

Hello altenbach,

 

I want to subtract the newest element from the element before it. I only want to use element 0 and 1. I am trying to calculate the derivative so what I was going to do was subtract the elements and divide them by the passed time. The array constantly gets new elements from measurements. The result is displayed and saved. The data type should be float.

0 Kudos
Message 3 of 11
(1,427 Views)

Your description is too ambiguous and confusing. Why can't you attach a simplified version of your code??

 

If the array constantly appends new elements, element 0 and 1 will never change after the first two steps unless you prepend the new data to the array, which is incredibly inefficient and not recommended.

0 Kudos
Message 4 of 11
(1,422 Views)

The array deletes elements so the 1st and 2nd element change. All I really want to know is how I can get just one number out of an array. I just want the 2nd element.

0 Kudos
Message 5 of 11
(1,416 Views)

So the array only has two elements? You can use index array to get the elements at index  0 and 1, then subtract them.

 

altenbach_0-1667685226612.png

 

 

If the array ever only has two elements, you don't really need an array.

 

altenbach_0-1667685002578.png

 

 

This is all very basic stuff. Have you tried any of the learning resource listed at the top of the forum?

 

0 Kudos
Message 6 of 11
(1,412 Views)

The array has 100 elements. I have tried using index array but when I used it, it only gave me 0 for the second element.

airplane603_0-1667685749643.png

 

I have tried these two

airplane603_0-1667685931114.png

 

 

0 Kudos
Message 7 of 11
(1,400 Views)

You really need to stop showing us useless truncated pictures with ambiguous wiring (we can't even see where the two blue constants are connected!!! )

 

Attach your VI or nobody will help you. I am out!

0 Kudos
Message 8 of 11
(1,383 Views)

@airplane603 wrote:

I am trying to calculate the derivative.


What problem are you trying to solve? This looks like a https://en.wikipedia.org/wiki/XY_problem and I think your experience will be better if you give the whole picture (in addition to the whole .vi file).

0 Kudos
Message 9 of 11
(1,337 Views)

@airplane603 wrote:

The array has 100 elements. I have tried using index array but when I used it, it only gave me 0 for the second element.

 


Why would that be an error? Maybe the second element was 0? If you are unsure, maybe this can help: https://www.youtube.com/watch?v=1Rx6AXhF31I (Using Debugging Tools in NI LabVIEW)

0 Kudos
Message 10 of 11
(1,335 Views)