LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing array elements value In labview

Solved!
Go to solution

Let's say we have an array of 3,10,8,2

im hoping to feed this array to a loo in which my daq assist is located . If we need to increase send signal to channel 1 and if we need to decrease send to channel 2 

so for this array start by sending Boolean true signal 3 times , then second element is 10 so send 7 (10-3) more times to channel 1 then next is 8 so decreases by 2(10-8=2) so send twice to channel 2 and finally since last value is 2 so it decrease by 6 (8-2=6) so send 6 to channel 1... 

how can I do that ? Is there an easy way ? Maybe we just need 1 channel let's say channel 1 with default value 0 . So first digital signal 3 times to channel one then rest then send 10 times then reset to default ... 

how do you reset to default after each iteration ? 

0 Kudos
Message 1 of 16
(5,487 Views)

To determine the difference between consecutive elements of a loop, you can auto-index your array with a 0 initialized shift register, and wire teh element to the right side whilst calculating the difference.

Example_VI_BD.png

 

The Absolute value function will allow you to find the magnitude of the difference. 

 

How are you deciding between Ch1 and Ch2? When you say "sending Boolean true signal 3 times" do you mean 3 digital high value pulses? You can send boolean pulses with the digital waveform nodes:

Example_VI_BD.png

Here I send 3 samples with Toggle - this alternates the signal. By default, the values are 0 and 1, so this means the output will be 0,1,0. The sample rate determines the rate of the waveform that is outputted whilst the number of signals determines the number of digital outputs you intend to use.

 


GCentral
Message 2 of 16
(5,472 Views)

Wow thank you so much for your explanations. No by sending signal I meant sending 1,1,1 when sample rate is 3. Or 1,1,1,1 when sample rate is 4

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

Ah - let me explain a little more clearly. I used 3 samples to send 1 pulse from low to high to low. If you want 3 pulses, and to end on low, you should wire a 7 to the input where I wired 3. This will give 3 high and 4 low values, or 3 pulses ending low.

 

Do you see what I mean?


GCentral
0 Kudos
Message 4 of 16
(5,440 Views)

@cbutcher wrote:

To determine the difference between consecutive elements of a loop, you can auto-index your array with a 0 initialized shift register, and wire teh element to the right side whilst calculating the difference.

Example_VI_BD.png

 

The Absolute value function will allow you to find the magnitude of the difference. 

 

How are you deciding between Ch1 and Ch2? When you say "sending Boolean true signal 3 times" do you mean 3 digital high value pulses? You can send boolean pulses with the digital waveform nodes:

Example_VI_BD.png

Here I send 3 samples with Toggle - this alternates the signal. By default, the values are 0 and 1, so this means the output will be 0,1,0. The sample rate determines the rate of the waveform that is outputted whilst the number of signals determines the number of digital outputs you intend to use.

 


In your first snippet, I'd toss the first element of the resulting array because it doesn't mean anything.  (The initial "zero" is a made-up number and doesn't represent real data.  The data starts from 3, not 0.)  What are your thoughts on this?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 16
(5,433 Views)

I'm not entirely sure, but the OP specified the values and pattern. It's true that taking the first value isn't the same as the others - they are differences while the first is just a replica, but that was the question


GCentral
0 Kudos
Message 6 of 16
(5,422 Views)

@cbutcher wrote:

I'm not entirely sure, but the OP specified the values and pattern. It's true that taking the first value isn't the same as the others - they are differences while the first is just a replica, but that was the question


Oh, I understand.  I was just curious about your opinion of my opinion.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 16
(5,413 Views)

billko wrote:

 

Oh, I understand.  I was just curious about your opinion of my opinion.  😉

Well, I suppose the truthful answer is I don't know what my opinion of your opinion is! But I sort of imagined that this question was counting with increment and decrement pulses, and so starting from zero sounded vaguely reasonable in my head. I'm not at all certain that's really what's going on, and I'm sure there are a wide range of situations in which I would indeed drop the first value (time taken to do something, like a reset as I saw in another thread a couple of days ago, for example - the first measurement was only the start whilst subsequent measurements were a stop and then a start).


GCentral
0 Kudos
Message 8 of 16
(5,411 Views)

I tried with auto indexing.. the pattern was 5,7,2 ...

i wanted it to show 5-7=2 , 7-2=5 but instead it showed 5-7=2 , 2-2=0 .This is my code

0 Kudos
Message 9 of 16
(5,358 Views)

test_BD.png

You need to change what you're wiring into the shift register!

 

This snippet will give 5-0 = 5, 7-5=2, 2-7=-5. If you instead want 0-5=-5, 5-7=-2, 7-2=5, you should use the Negate primitive on the output of the subtraction.


GCentral
Message 10 of 16
(5,341 Views)