LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sorting array number in different ranges

Solved!
Go to solution

Hello,

I want to assign one color to several ranges of number. I would like to know the best way to accomplish it.

I created one example.

In this example, I have one array with numbers and I assign one color to values:

<2.5 green

2.5 - 5 yellow

5-7.5 orange

7.5-10 red

 

It is only one example and I have more than 4 ranges in my application. I would like to know if it exists another way to sort the array than using several case structures...

 

Thanks for help!.

Regards.

 

0 Kudos
Message 1 of 15
(4,919 Views)

Greetings, have you thought of using the "RGB to coulour" VI, and multiply the input by a constant? That way it would dinamically assign a colour without having a ton of cases, you just need to find the right constant to have a good distinction 

0 Kudos
Message 2 of 15
(4,894 Views)
Solution
Accepted by Fonsi

@Daikataro wrote:

That way it would dinamically assign a colour without having a ton of cases, you just need to find the right constant to have a good distinction 


(That assumes that the ranges are all of equal lenght and that the desired colors are in numerical order. Way too restrictive!)

 

I would use threshold array on an array of boundary values and index into an array of colors. Here's an example:

 

 

 

 

(Note that all values >10 will also be red. modify as needed if you want yet another color for >10 or similar)

 

Adjusting the colors or boundaries is as simple as changing the array diagram constants.

Download All
Message 3 of 15
(4,888 Views)

I just wrote exactly the same code as Altenbach, but it took me longer, of course.

 

However, one possible small improvement in Altenbach's code: you can make the last two elements of the array the same value, and then any input over that value will be assigned the last color in the array.

sort_ranges_color.png

0 Kudos
Message 4 of 15
(4,864 Views)

@nathand wrote:

I just wrote exactly the same code as Altenbach, but it took me longer, of course.

 

However, one possible small improvement in Altenbach's code: you can make the last two elements of the array the same value, 


Why would that be an improvement? The last element just needs to be equal or larger (e.g. 10, as in my example), the actual value (within reason) does not matter. It is actually confusing for code readability to have two identical values in there.

0 Kudos
Message 5 of 15
(4,849 Views)

Sorry, improvement was the wrong word, I should have said alternative. Personally I think it's clearer since then you don't wonder what's special about the value 10, but the results are exactly the same either way.

 

I did discover, however, that you cannot use +Inf.

0 Kudos
Message 6 of 15
(4,838 Views)

@nathand wrote:

I did discover, however, that you cannot use +Inf.


Not just Inf. Any huge number (e.g. 1e20) will cause the interpolated value to be so close to the lower index value that is is identical within DBL resolution and rounding to +Inf adds nothing.

0 Kudos
Message 7 of 15
(4,829 Views)

Would using Search Ordered Table.vi solved the Inf issue?

 

Using Ordered Table.png

 

Ben64

0 Kudos
Message 8 of 15
(4,815 Views)

altenbach escribió:

@Daikataro wrote:

That way it would dinamically assign a colour without having a ton of cases, you just need to find the right constant to have a good distinction 


(That assumes that the ranges are all of equal lenght and that the desired colors are in numerical order. Way too restrictive!)

 

I would use threshold array on an array of boundary values and index into an array of colors. Here's an example:

 

 

 

 

(Note that all values >10 will also be red. modify as needed if you want yet another color for >10 or similar)

 

Adjusting the colors or boundaries is as simple as changing the array diagram constants.


Hello guys!.

Thanks for all the responses.

Altenbach give the solution. I added another case if I add negative values in ranges. I put one solution, I think it is effcient solution.

But, what happen if the ranges are of the different lenght?

 

Instead use 2.5,5, 7.5 and 10. use 2, 5, 9, 10...

 

Regards.

0 Kudos
Message 9 of 15
(4,769 Views)

@Fonsi wrote:

But, what happen if the ranges are of the different lenght?

 

Instead use 2.5,5, 7.5 and 10. use 2, 5, 9, 10....


With that code, it does not matter.  It always rounds up.  So if the number is between the first and second number, you will have the second color.


GCentral
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
0 Kudos
Message 10 of 15
(4,761 Views)