LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to split an element into two elements

Solved!
Go to solution

I am currently working with a logic analyzer which outputs data in a 2D array. The problem is the only way I can receive the data is very inconvenient for analysis. I would like to separate the data so that each column corresponds to a certain value I am measuring. So what I really need to do is split a column into two columns. Basically if I have,

 

12345678          12345678

12345678          12345678

12345678          12345678

12345678          12345678

 

And what I want is:

 

1234     5678       1234       5678

1234     5678       1234       5678

1234     5678       1234       5678

1234     5678       1234       5678

 

I have been searching for a solution for quite some time, any suggestions??

 

0 Kudos
Message 1 of 12
(5,050 Views)

You could use two for loops to access each element of the 2D array. Once accessed you could use the "Split Number Function" to split the one element up into two and then rebuild the array. 

 

I don't have acces to my computer with LV right now, but if I can I will put together a better example of what I am trying to describe above.

 

Below is just kind of an example that shows how to access each element of a 2D array using auto indexing.

 

0 Kudos
Message 2 of 12
(5,045 Views)

If you are dealing with integer types you can use the split function on the Data Conversion palette. Once this is done, run the output 2d arrays into an auto-indexed for loop. Use the "Interleave 1d Array function to piece the split 2d arrays back into a single 2d array. See attached code. If this doesn't do what you asked, then please post a small LabVIEW example for us.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
0 Kudos
Message 3 of 12
(5,040 Views)
Solution
Accepted by duffy21

@Charles_CLD wrote:

If you are dealing with integer types you can use the split function on the Data Conversion palette.


Woah... what??  That split function isn't going to work.  If you have the base-10 value 12345678, splitting it isn't going to produce 1234 and 5678.  You could of course pretend that the base-10 values are actually base-16 in order to make the split work, but that's going to require a string conversion, and at that point it's easier just to split the string, like this:

split string.png

0 Kudos
Message 4 of 12
(5,023 Views)

You did not say what the datatype of the 2D arrays is, so we have to guess. Let's assume it's positive integers with exactly 8 decimal digits. 😄

 

Here's what I would probably do. Modify as needed.

 

Message 5 of 12
(5,010 Views)

Thanks! The data is actually a U8 format so I ended up converting it to a string and splitting it that way!

0 Kudos
Message 6 of 12
(4,974 Views)

@duffy21 wrote:

Thanks! The data is actually a U8 format so I ended up converting it to a string and splitting it that way!


You can still use exactly my method. (Going to string and back is an extreme detour.)

 

Of course your statement makes no sense, because U8 is insufficient to display the numbers you showed us. 😉

Message 7 of 12
(4,969 Views)

@altenbach wrote:

 

Of course your statement makes no sense, because U8 is insufficient to display the numbers you showed us. 😉


To be fair, when he mentions a Logic Analyzer it kind-of, sort-of follows (to those versed with those things) that 12345678 is then referring to bits in the data (usual format) so the problem described is simply splitting bytes into nibbles.

 

You can do mod math obviously, but I often like lookup tables when dealing with byte operations since I know the size is bounded to a cozy 256 elements.

0 Kudos
Message 8 of 12
(4,961 Views)

See also my comments here.

 

 

0 Kudos
Message 9 of 12
(4,951 Views)

Yes I suppose you can do that as well, but what using the string splitting allows me to do very easily is divide it un-evenly. What I mean is that what I am actually doing is taking something that looks like this:

 

00101100          110

00101100          110

00101100          110

00101100          110

 

And turning it into this:

 

00       101100          1         10

00       101100          1         10

00       101100          1         10

00       101100          1         10

 

So while I may not know the exact correct terminology to use when referring to the data, I do know that it worked! 🙂

 

And for the record, 'he' is actually a 'she' 😉

 

 

0 Kudos
Message 10 of 12
(4,940 Views)