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: 

How to convert string with numbers into 2D boolean array

Solved!
Go to solution

Hello,

i have as input a string with comma separated numbers 1..192 (starting at 1).

 

This string has to be converted into a 2D-boolean array. Each numer that appears should be true, the rest false.

The 2D array consists 4 times of 0..47 booleans.

 

Numbers 1..48        --> [0..47]  [0]
Numbers 49..96     --> [0..47]  [1]
Numbers 97..144   --> [0..47]  [2]
Numbers 145..192 --> [0..47]  [3]

 

So a input string of "1, 49, 97,145" should set all [0][0..3] to true.

 

How can this be easy/fast solved?

 

Thanks for help

0 Kudos
Message 1 of 5
(3,517 Views)
Solution
Accepted by RavensFan

Break the string of numbers into an array of numbers.  (Spreasheet String to Array).

 

In a For Loop, index through each number in that array.  Use In Range and Coerce to see if it is in the range of numbers.  (You might want to put this in a For Loop as well auto indexing through the ranges).  If it is in Range, then use Replace Array subset to turn the corresponding element into a True.  If not, do nothing.  Maintain the boolean array in a shift register.

 

Repeat that step for each number in your array.

 

(Is this a class assignment?)

0 Kudos
Message 2 of 5
(3,509 Views)

Hi,

thanks for the help. It is almoste working,

Now i have four "In Range and Coerce" for the for ranges which create four arrays.

Currently i have a Buld Array" to create a 2D-Array of the four 1D arrays.

But: How can i change the 2D array that it its not a[0..3[0..47] but a [0..47[0..3] array?

Thx

0 Kudos
Message 3 of 5
(3,458 Views)

Can you attach the VI you have so far?

 

If I can see how you have the data structured, then I can propose an idea of how to work with it.

0 Kudos
Message 4 of 5
(3,455 Views)

Solved.

I searched "Transpose 2D Array"

 

0 Kudos
Message 5 of 5
(3,449 Views)