From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

making a block diagram: sequential array stay a value

Solved!
Go to solution

Hi, 

 

I'm trying to make a block diagram to get sequential outputs from same length of sequential inputs.

 

It seemed easy to make it before I actually was wiring array, but I stuck.

 

So what I want to do is this.

 

For example, sequential input value goes in say 5,4,3,2,1,2,3,4,3,2,.....

 

I want to get sequential output value as 5,4,3,2,2,2,2,2,....

 

Basically when input value hits 2 one time during sequential input, output needs stay at 2 whatever values goes into later.

 

Can someone help me out?

 

Thanks,

 

0 Kudos
Message 1 of 13
(2,748 Views)
Solution
Accepted by topic author coffee3am
Hi,
I World recommend to use a for Loop with Auto Index. If the value becomes 2, store the boolean Information in a Shift Register and provide 2 at the Output of the Auto Index Tunnel if the value of the Register is true. This should solve the Problem.

Tyler
Certified LabVIEW Architect
Message 2 of 13
(2,730 Views)

Thank you for your reply.

 

I'm still having a problem though, since the input values are from other part of diagram which is in a big for loop. 

 

structure looks like this,

 

dt = 500 ms

 

iteration          1    2     3     4     5     6     7    8     9 .....

input value      5    4     3     2     1     2     3    2     5 ......

target             5    4     3     2     2     2     2    2     2......

 

It seems explaning my situation is more complicated. 😞

 

 

0 Kudos
Message 3 of 13
(2,719 Views)

Hi coffee,

 

well, drawing a sketch on a sheet of paper sometimes makes things a lot easier...

 

Some pseudo-code may guide you:

 

flag := false;
FOR i = 0 to arraylength-1
 IF array[i] = 2 OR flag=true
 THEN
   output[i] = 2;
   flag :=true
 ELSE
   output[i] = array[i]
 ENDIF
NEXT i

 

General comments:

- Storing items from one iteration of a loop to the next is done with a shift register in LabVIEW.

- All the array indexing is done by "auto-indexing" tunnels of FOR loops in LabVIEW.

- Go through online lessons available at NI.com, there are several of them.

- Look at the examples coming with LabVIEW, there is a hugh number of them...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 13
(2,708 Views)

Thanks for your reply.

 

I wrote this code orignally in Matlab, and I'm trying to tranform into Labview code. 

 

I never had a chance to learn how to use shift registers for loop in Labview before, so that is the dead-end...:(

 

I should look for examples of them.

 

K

0 Kudos
Message 5 of 13
(2,696 Views)

Hi GerdW,

 

I tried to make a blocks using shift register, but it doesn't work...

 

Could you check my vi to see where is the problem?

 

Thanks,

 

K

0 Kudos
Message 6 of 13
(2,678 Views)

Try this (LV2011):

 

 

 

The boolean value in the shift register changes to TRUE the first time a 2 is encoutered and stays true after that.

 

(Also note that I changed the numerics to integers. Equal comparisons on floating point numbers can lead to unexpected results ;))

Download All
Message 7 of 13
(2,675 Views)

Thank you for showing vi.

 

Unfortunately I still couldn't solve this though. 

 

The input ant output of your vi is in form of array, so a for loop with auto indexing can make it working. 

 

My problem is like real-time task that the input and output need to be a value with some time delay, so it seems not working with it....:(

 

In other words the inputs goes into this vi are like 5(500 ms), 4(500ms), 3(500ms), 2(500ms), 1(500ms), 2(500ms)...so on.

 

The output I want to get is similar 5(500 ms), 4(500ms), 3(500ms), 2(500ms), 2(500ms), 2(500ms)...so on.

 

I tried to modify your vi, no luck yet. Smiley Sad

 

K

0 Kudos
Message 8 of 13
(2,642 Views)

Hi coffee,

 

a picture might say more than a thousand words. Why don't you attach your current VI or a picture of the block diagram?

 What kind of inputs do you have? Strings containing "5(500ms)"?

 

But anyway: the same pattern applies, regardless of autoindexing arrays otr just scalars: keep a flag in a shift register to store "value already found" signal.

The example shown before uses scalars inside the loop, so you only have to use that...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 13
(2,637 Views)

@coffee3am wrote:

The input ant output of your vi is in form of array, so a for loop with auto indexing can make it working. 


Same thing, basically:

 

  1. replace FOR loop with while loop
  2. remove arrays
  3. Connect scalar input to the lower terminal of the equal node
  4. Connect scalar output to the output terminal of the select node.
  5. Rest stays the same (shift register, etc)

 

Message 10 of 13
(2,632 Views)