# How to determinate standard deviation above and below mean classes programatically

I have an array of float from wich I calculate the mean and the standard deviation. The user can specify a number of class varying between 2 and 8. The min and max values of each class is calculated by a number of standard deviation above and below the mean.

Ex:

nbr_classes = 4;
mean = 10;
min_value = 1
max_value = 10
std_deviation = 2

class_1_min = min_value
class_1_max = mean - 2*std_deviation

class_2_min = class_1_max
class_2_max = mean - std_deviation

class_3_min = class_2_max
class_3_max = mean + std_deviation

class_4_min = class_3_max
class_4_max = max_value


I would like to create a function that would do that programatically, knowing that number of classes can be odd

I don't know what language you are using. Typically one would use the switch statement.

switch(case): { case exp1: \\statements for case 1\\ break;

case exp2: \\statements for case 2\\ break; ...

}

You can also set a fail safe case. Some languages do not support switch in which case you can just use a long set of if-elseif statements

• you mean setting one case by number of classes between 2 and 8? Thats interesting, in fact I was scratching my head to do it in a loop for i < nbr_classes.length. By the way its for javascript, so yes switch could be a solution Aug 15, 2014 at 19:27
• Yes, you specify case 2: blah blah ; The advantage over if/elseif is improved readability.
– Sid
Aug 15, 2014 at 19:42