03-23-2016 04:43 PM
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.
Solved! Go to Solution.
03-23-2016 05:04 PM
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
03-23-2016 05:07 PM - edited 03-23-2016 05:19 PM
@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.
03-23-2016 05:22 PM
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.
03-23-2016 05:51 PM
@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.
03-23-2016 06:01 PM
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.
03-23-2016 06:09 PM
@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.
03-23-2016 06:38 PM
03-24-2016 07:29 AM
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.
03-24-2016 07:34 AM
@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.