From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

working with arrays

Solved!
Go to solution

What is the best method of re-indexing an array for instance 

I want to change an array from [a,b,c,d,...]

to an array in the following form 

[a,0,b,0,c,0,d,0,...]

 

Thank you...

0 Kudos
Message 1 of 5
(2,283 Views)
Solution
Accepted by janabiam

 

interleave.png

 

Message 2 of 5
(2,276 Views)

Thank you, this was very helpful.


@Artem.SPb wrote:

 

interleave.png

 


 

0 Kudos
Message 3 of 5
(2,260 Views)
Solution
Accepted by janabiam

Of course Artem's solution is most universal and works for most datatypes (numerics, strings, etc. interleaving with other values, etc.).

 

Just for fun, here are two more versions for numeric arrays only:

 

This one is potentially dangerous (if the input contains NANs, INFs, -INFs, etc the interleaved element will be NaN), OTOH, it's less code.

 

interleave.png

 

 

Here's a cute one. See if you figure it out 😄

 

interleaveCDB.png

Message 4 of 5
(2,221 Views)

The one that uses the typecasting is very interesting. 

First you created a complex numbers a+0i, b+0i, c+0i, d+0i

then you fed the typecast type port (on top) from the real part, this will make the typecasting to real numbers. Therefore, instead of being written in complex form the real and imaginary are written successively in one column which made it a,0 b,0,c,0,d,0.

 

Thank you very much, I really appreciate your creativity. 

 

Ameer 

0 Kudos
Message 5 of 5
(2,213 Views)