LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Analysis

Solved!
Go to solution

I am trying to create a VI that takes a 1D array input and generates a 2D array output. The array input is an array with just 0's and 1's. What I want the output to be is an array that has 0's and 1's on its first row and on the second row a count of the consecutive number of either 0 or 1 on the input array. This might sound confusing, so I'll give an example. 

 

input

[1  1  0  1  1  1  1  0  0  0  1  0  0]

 

output

row1 [ 1  0  1  0  1  0]

row2 [ 2  1  4  3  1  2]

 

So basically the first row is just 0's and 1's in alternatig order (it starts with whatever is on the zeroth position on the input array) and the second row gives the number of consecutive 1's i have before the next 0, or the number of consecutive 0's before the next 1 on the input array. 

 

 I thought about using a case structure but I am not so sure how to set it up, so any tips would be helpful. 

0 Kudos
Message 1 of 10
(2,797 Views)

@sebas98 wrote:

 I thought about using a case structure but I am not so sure how to set it up, so any tips would be helpful. 


A case structure selects from alternative code and has really nothing to do with your problem. All you probably need is a  FOR loop, shift register, conditional tunnel, and some trimmings.

 

Sorry posting by phone, cannot make example. Still, should only take a minute.

0 Kudos
Message 2 of 10
(2,789 Views)

Could you be a bit more specific? 

Thanks

0 Kudos
Message 3 of 10
(2,766 Views)

@sebas98 wrote:

Could you be a bit more specific? 


I was significantly more specific than your blurb about "case structures". 😉

I am in the middle of something else, but maybe I can make a simple example later.

 

What is your LabVIEW skill level? What is your LabVIEW version?

 

Also note that the chance of a good and quick answer increases dramatically if you also do some of the work. For example by attaching a simple VI that contains typical default data and expected results. Now we would know: (1) the actual datatype of the input, U8 array? Boolean? EXT?), (2), your LabVIEW version, (3) How you want the output (rows, columns, datatype, etc.).

0 Kudos
Message 4 of 10
(2,760 Views)

I began using labview about two weeks ago, so my skill level is pretty basic. I am using Labview 2018.

This would be a sub-VI to a bigger VI. The input array would be of type double, as well as the output array. The output array should be in just two rows.

 

Thanks for your help. 

Sorry if I seemed rude before. 

0 Kudos
Message 5 of 10
(2,747 Views)

There are many simple ways to do this, here's one possibility:

 

Process_0-1.png

 

(once you tell us your LabVIEW version, I'll attach the code)

0 Kudos
Message 6 of 10
(2,746 Views)
Solution
Accepted by topic author sebas98

@sebas98 wrote:

The input array would be of type double, as well as the output array. The output array should be in just two rows.


OK, did not see your response. You can definitely make my code into a subVI.

(Note that you might need to tweak a few things if other numbers can occur in the input. In principle it will work with any number of different values, not just 0,1)

 

It is wasteful and potentially dangerous to represents 0, 1 in DBL. Why can't you use integers? You should!

Message 7 of 10
(2,739 Views)

Thanks a lot, I'll try it out tomorrow when I get back to the lab, and I'll let you know how it goes. 

I was using doubles just because whenever there is a number I automatically select it. I don't really have a criteria to chose the type, so I just go with double always. But if you recommend using integers I'll go with it. 

0 Kudos
Message 8 of 10
(2,734 Views)

Make sure you completely understand the function and purpose of every single code element. A good exercise. 😉

 

Feel free to return and ask questions if anything is not clear.

0 Kudos
Message 9 of 10
(2,728 Views)

@sebas98 wrote:

I was using doubles just because whenever there is a number I automatically select it. I don't really have a criteria to chose the type, so I just go with double always. But if you recommend using integers I'll go with it. 


Doubles will give you problems. Use doubles if your data can have floating data. If not, don't.

 

Especially comparison of doubles is not recommended (in any programming language, AFAIK). A double displaying 1 and another one displaying 1 might not be equal. Be warned...

 

Besides that doubles are less efficient in both CPU use and memory. 

Message 10 of 10
(2,688 Views)