LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Organising an array

I currently have an output array which is the product of 3 input channels (lets call them a, b and c.)  The output array produces the data so that it is in the order a1 b1 c1 a2 b2 c2......an bn cn.  I need to organise this data so that it is split into three arrays, one for each channel, with the data in chronological order, i.e. a1 a2 .....an.  I also need the process to be dynamic enough that it can cope with the number of channels changing each time the program is run.  I am sure there must be an easy enough solution to this problem I am just not experienced enough to know what it is. Any help would be great.

0 Kudos
Message 1 of 8
(3,435 Views)

What you want to look at is the reshape array function.  This will take a 1-D array and reshape into a 2-D array where each row will contain one of the channels which you can then index out.

 

Message Edited by Ravens Fan on 01-20-2010 12:04 AM
0 Kudos
Message 2 of 8
(3,430 Views)

Hi jnew8916,

   Check this out..

 

 

T hanks and regards,

srikrishnaNF

Regards,
Srikrishna


0 Kudos
Message 3 of 8
(3,416 Views)

Simply use "decimate array" resized to three outputs:

 

Message Edited by altenbach on 01-20-2010 12:40 AM
0 Kudos
Message 4 of 8
(3,408 Views)

jnew8916 wrote:

 I need to organise this data so that it is split into three arrays, ...also need the process to be dynamic enough that it can cope with the number of channels changing each time the program is run.


This will not be possible, because you cannot have an variable number of output arrays. What you can have, however, is a 2D array with variable number of columns (one for each channel for example). (This is similar to Ravens solution above, but slightly cleaner. You cannot have a fractional number of elements, so why go to orange? 😉 I also think Ravens has the indices to the reshape function reversed so please verify)

 

Let's assume that the number of elements in the input is divisible by the number of channels, so you would do the following:

 

 

 

The above would truncate the partially filled tail if the number of elements is not divisible. In this case  you could pad to the next higher integer in order not to lose any data as follows:

 

 

 

If you later need to operate on each channel in a loop, you might want to transpose the 2D output array.

Message Edited by altenbach on 01-20-2010 12:59 AM
Download All
Message 5 of 8
(3,402 Views)

altenbach wrote:

This will not be possible, because you cannot have an variable number of output arrays. What you can have, however, is a 2D array with variable number of columns (one for each channel for example). (This is similar to Ravens solution above, but slightly cleaner. You cannot have a fractional number of elements, so why go to orange? 😉 I also think Ravens has the indices to the reshape function reversed so please verify)

 


True, the orange was just a byproduct of using the division function.  I was thinking about the quotient/remainder function, but I was getting hung up because I usually think of it more for the remainder aspect rather than the quotient.  It's possible the indices of the reshape array need to be swapped, just a matter of whether the channels are in row or columns.  I checked the way I wired it and each channel seemed to occupy its own row.  Then its just a matter of what is being done with the data later as to whether channels are easier to work with in rows or columns.

0 Kudos
Message 6 of 8
(3,365 Views)

Ravens Fan wrote:

It's possible the indices of the reshape array need to be swapped, just a matter of whether the channels are in row or columns. 


No, it really matters. The input data has no rows and colums because it is 1D and we know how the data is arranged (interlaced!)

(Make sure you test with data where #of rows != # of columns!)

 

For example if you have 2 channels and the following input data:

 

1,2,3,4,5,6,7,8

 

Using your code, you would get:

 

1,2,3,4

5,6,7,8

 

or transposed:

 

1,5

2,6

3,7

4,8

 

Both are incorrect according to the problem description.

 

With my code, you would get:

 

1,2

3,4

5,6

7,8

 

or transposed

 

1,3,5,7

2,4,6,8

 

Which is as required.

Message Edited by altenbach on 01-20-2010 07:58 AM
Message 7 of 8
(3,358 Views)

You're correct.  I swear I checked this last night when I made up the example.  But I used a rather simple 2 channel, 3 sample array, and only used single digits, and it appeared okay.  I think I got the channel vs. sample mixed up and told it that it was 3 channels when in reality I looked at the example as a 2 channel.

 

The attachment is an example I just made to confirm this using the letter channel name and digit sample# in strings.

 

I hope the original poster and others will see this as an example to thoroughly test any code to make sure it does what they want.  I find it necessary when working with 2-D arrays because I can quickly get confused as to what the row dimension means versus the column dimension.  And even then I can still get them mixed up.

0 Kudos
Message 8 of 8
(3,336 Views)