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
Did you mean:

## Replace each 0 and 1 in an array with n number of 0s and 1s

01001

and I want to replace each 1 and 0 with 2  ( might be 10000)  number of0s and 1s. so the result is

0011000011

Could you please help me to implement this in LV . As mentioend I should be able to repeat the bits as many time as specified . 2 times or 100000 times

Thanks

Message 1 of 8
(2,781 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

This sounds like homework, but i'll give you a hint -

You need to iterate through the array and create a seperate array based on the individual elements. To do that, you'll need a for loop, a case structure, initialize array, and build array.

You should be able to take it from here...

Philip
CLD
Message 2 of 8
(2,775 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

VI Attached.  Pretty easy logic to claim help  :[  I would suggest u to learn LabVIEW fundamentals. Read the help context and pratice with examples already shipped. 🙂

Message 3 of 8
(2,753 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

@p-rose wrote:
...To do that, you'll need a for loop, a case structure, initialize array, and build array.

Two for-loops will do, actually

Message 4 of 8
(2,739 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

Or you could just interleave the array with a copy of itself. See attachment.

Best regards,

Jarle Ekanger, MSc, PhD, CLD
Flow Design Bureau AS

- "The resistance of wires in LabVIEW is not dependent on their length."
Message 5 of 8
(2,729 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

I would use Initialize Array.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 8
(2,710 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

Or, if you want to be fancy, turn the digit array into a string, use search-and-replace (2X) to add your digits, then turn the resulting string back into a number array.

Cameron

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
Message 7 of 8
(2,692 Views)

## Re: Replace each 0 and 1 in an array with n number of 0s and 1s

Most cleaner and simple solution has been posted by crossrulz

Message 8 of 8
(2,670 Views)