07-18-2013 02:10 PM
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,
K
Solved! Go to Solution.
07-18-2013 02:32 PM - edited 07-18-2013 02:33 PM
07-18-2013 03:23 PM
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. 😞
K
07-18-2013 04:14 PM - edited 07-18-2013 04:16 PM
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...
07-18-2013 04:51 PM
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
07-18-2013 06:24 PM
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
07-18-2013 06:50 PM - edited 07-18-2013 06:53 PM
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 ;))
07-19-2013 01:39 AM
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.
K
07-19-2013 01:46 AM - edited 07-19-2013 01:48 AM
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...
07-19-2013 01:57 AM
@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: