LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to demultiply an array

Hei,
 
i have a 2D array, which i want to demultiply:
for example, the first row have 1000, 2000, 3000, 4000. the second row have 1, 2, 3.
i want an output 2D array which would look like:
1000, 1000, 1000, 2000, 2000, 2000, 3000, 3000, 3000, 4000, 4000, 4000
1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3.
 
of course i would like this demultiplication to happen for a 3 row system as well and so forth.
i managed to do it quite complicatedly using series of for loops, but at the end i got too much bugs in it...
need a clean solution, if anybody has an idea
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 1 of 9
(3,866 Views)
Experimentation is always a good place to start for working with arrays in LV. One of the nice things about it is that it's easy to build a little prototype when you're not sure what the behavior is going to be for a given array function.

Your question about demultiplying can very simply be done using two Transpose Array functions and a Build Array. No loops, nothing else. Play around a little and see if that helps... 🙂

Message Edited by Jarrod S. on 04-29-2007 08:25 PM

Jarrod S.
National Instruments
0 Kudos
Message 2 of 9
(3,848 Views)
Sorry, I am not familiar with the term "demultiply". It is also not possible to have a 2D input array input where one row contains 4 elements and the second row contain 3 elements.
 
For this reason, I am using 2 1D array inputs. Maybe this is something along the lines you need. Who knows? 🙂
 
 

Message Edited by altenbach on 04-29-2007 06:54 PM

Message 3 of 9
(3,844 Views)
Good catch about the row sizes. What I had in mind won't work unless all the rows are of equal length. If all the rows are of equal length, though, my technique would work for any number of rows. I'll post the trivial VI, but unfortunately I only have 8.2.1 and I'm still getting the hang of the whole screenshot business on Macs :). I'll post a screenshot when I can.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 9
(3,835 Views)
Jarrod,
 
Your algoritm is not the same, because you are keeping colum values together. For example for an input array of
 
ABC
DEF
 
your code produces
 
ABCABCABC
DEFDEFDEF
 
While (given 1D arrays ABC and DEF), mine would produces
 
AAABBBCCC
DEFDEFDEF
 
in apparent better agreement with the example in the original post. I still need to find a good definition for "demultiplying", though. 😉
0 Kudos
Message 5 of 9
(3,829 Views)
Hello Guys,
 
Thanks a lot for your answers. they help me.
the problem of Altenbach solution, which i come upon at some point in my experimentation, is that i am bound to use a certain number of 1D arrays in advance, in this case 2.
the problem begin when i have several (not known in advance) such 1D arrays, and i want to demultiply them (or interleave-multiply them?...i could not find a good definition for the operation).
again an example of the kind:
1000, 2000, 3000,
1, 2, 
A, B,
 the outcome array would need to be :
1000, 1000, 1000, 1000, 2000, 2000, 2000, 2000, 3000, 3000, 3000, 3000 
1, 1, 2, 2,1, 1, 2, 2, 1, 1, 2, 2,
A, B, A, B, A, B,
 
As Altenbach said, trying to begin with a 2D array i stumble across a lot of Zeros which i definitely need to keep out (unless it is one predefined by the user).
 
from your answer i understand i have no choice but limit the nb of 1D arrays i am going to use. but then other problem occurs if the array is empty...
 
Gabriel
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 6 of 9
(3,821 Views)
Hi Altenbach,

Thanks. I realized that as soon as I woke up this morning. The brain seems to filter these things out at night! Not sure how that slipped through the cracks.
Jarrod S.
National Instruments
0 Kudos
Message 7 of 9
(3,802 Views)
You're always going to have a problem with a 2D array. In your example problems and solutions, the resulting rows don't have the same number of elements. All rows in a 2D array must have the same number of rows. Period.

You have a couple options.

The first is the most popular, and that is to have an array of clusters of 1D arrays instead of a 2D array. The advantage there is that the 1D arrays in the clusters, which represent the rows, don't have to have the same length as each other. The disadvantage is that you can't directly index down to individual elements or perform various other array operations. You have to index, unbundle the cluster, then continue.

The other idea would be to stick to a 2D array, but have an extra 1D array that keeps track of the relevant length of each row. For instance, the if you wanted to "ignore" the zeros in the example below, you could have a length array as follows:

1 1 2 2 3 3
A B A B 0 0
X Y 0 0 0 0

Length array: [6, 4, 2]

Then you just have to make sure this extra array stays synchronized with your 2D array.

P.S. Your example solutions don't seem to have any rhyme or reason to them that I can discern. Are you just duplicating row elements a certain number of times? If so, what number? Is there any way of knowing?

Message Edited by Jarrod S. on 04-30-2007 09:38 AM

Jarrod S.
National Instruments
0 Kudos
Message 8 of 9
(3,801 Views)

Hello Jarrod,

thanks for your remarks. i did actually exactly what you just proposed, meaning i have a 1D array that keep track of my 2D info. that was the best solution to allow multiple rows (unknown in advance). but it seems not to work ok, so i came back to a solution with 5 times 1D arrays, and i "demultiply" them the ugly way, using 5 for loops. see picture.

i am not sure i understood your ps question. i will tell you what i do with these arrays, and tell me if this what you wanted to know:

the idea is to make a 1D, 2D, or multidimensional search for fitting a function, or exploring parameter space. in other word, each row in the array includes the possible search values of a certain parameter (defined and kept track somewhere else). then, for each parameter of this row i want to change all other parameters from the other rows.

of course it make little sense to search for more than 5Dimensions, therefore i dont care about this limitation.

Gabriel

Message Edited by Gabi1 on 04-30-2007 10:49 AM

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 9 of 9
(3,783 Views)