# controlrules

Western Electric and Nelson control rules

## Description

returns violation indicators for the points in the numeric vector `R`

= controlrules(`rules`

,`X`

,`cl`

,`se`

)`X`

,
using the rules in `rules`

, center line values `cl`

and
standard errors `se`

. If `X`

contains
*n* points and `rules`

contains
*m* rules, then `R`

is an
*n*-by-*m* logical matrix, where
`R(i,j)`

has the value `true`

(logical
`1`

) if point `i`

violates rule `j`

,
and a value `false`

(logical `0`

) if it does not. If
`rules`

contains only one control rule, then `R`

is
a logical vector of length *n*.

`[`

additionally returns a cell array containing the names of the applied control rules.`R`

,`appliedRules`

] = controlrules(___)

## Examples

### Use Western Electric Control Rule

Load the `parts`

data set.

`load parts;`

Create an X-bar chart with `controlchart`

using the `we4`

rule to mark out of control measurements. Return the subgroup statistics and plot data.

`[stats,plotted] = controlchart(runout,rules="we4");`

The software marks the out of control points marked with a red circle. Display the subgroup numbers of the out of control points.

find(plotted.ooc)

`ans = `*4×1*
2
21
25
27

Use `controlrules`

to identify the measurements that violate the `we4`

control rule.

```
R = controlrules("we4",plotted.pts,plotted.cl(1),plotted.se(1));
I = find(R)
```

I = 27

The subgroups 2, 21, and 25 are out of control since they are outside the control limits delineated by the red lines. Subgroup 27 is in violation of the `we4`

control rule, since it is the last of eight consecutive points that lie above the center line.

## Input Arguments

`rules`

— Control rules

character vector | string scalar | string array | cell array of character vectors

Control rules, specified as a character vector, string scalar, string array, or cell array of character vectors containing one or more of the following values.

Value | Violation Condition |
---|---|

`"we1"` | |

`"we2"` | Two of three points above |

`"we3"` | Four of five points above |

`"we4"` | Eight of eight points above `cl` |

`"we5"` | One point below |

`"we6"` | Two of three points below |

`"we7"` | Four of five points below |

`"we8"` | Eight of eight points below `cl` |

`"we9"` | 15 of 15 points between |

`"we10"` | Eight of eight points below |

`"n1"` | One point below |

`"n2"` | Nine of nine points on the same side of `cl` |

`"n3"` | Six of six points increasing or decreasing |

`"n4"` | 14 points alternating up or down |

`"n5"` | Two of three points below |

`"n6"` | Four of five points below |

`"n7"` | 15 of 15 points between |

`"n8"` | Eight of eight points below |

`"we"` | All Western Electric rules (beginning with the letters
`"we"` ) |

`"n"` | All Nelson rules (beginning with the letter
`"n"` ) |

For the control rules that involve more than a single point, a rule
violation at point `i`

indicates that the set of consecutive points
ending at point `i`

trigger the rule. `R(i)`

is
`true`

only if the point `i`

is one of the points
that violates the rule's condition.

Any point whose `X`

, `cl`

, or
`se`

value is `NaN`

is not counted in rules that
involve more than a single point, and always has an `R`

value of
`false`

(logical 0).

**Example: **`rules=["we","n"]`

**Data Types: **`char`

| `string`

`X`

— Points to evaluate

numeric vector

Points to evaluate, specified as a numeric vector.

**Data Types: **`single`

| `double`

`cl`

— Center lines

numeric vector | numeric scalar

Center lines, specified as a numeric vector that has the same length as
`X`

. You can also specify `cl`

as a numeric
scalar. In this case, the software uses the same value for all points.

**Example: **`cl=1.5`

**Data Types: **`single`

| `double`

`se`

— Standard errors

numeric vector | numeric scalar

Standard errors, specified as a numeric vector that has the same length as
`X`

. You can also specify `se`

as a numeric
scalar. In this case, the software uses the same value for all points.

**Example: **`se=2.5`

**Data Types: **`single`

| `double`

## Output Arguments

`R`

— Control rule violation indicators

logical matrix | logical vector

Control rule violation indicators for the points in `X`

, using
the rules in `rules`

, center line values `cl`

, and
standard errors `se`

. If `X`

contains
*n* points and `rules`

contains
*m* rules, then `R`

is an
*n*-by-*m* logical matrix, where
`R(i,j)`

has the value `true`

(logical
`1`

) if point `i`

violates rule
`j`

, and a value `false`

(logical
`0`

) if it does not. If `rules`

contains only one
control rule, `R`

is a logical vector of length
*n*.

`appliedRules`

— Applied control rules

cell array of character vectors

Applied control rules, returned as a cell array of character vectors. If
`rules`

includes `"we"`

or `"n"`

,
all of the associated individual rules are included in
`appliedRules`

.

## Version History

**Introduced in R2006b**

## See Also

## MATLAB 命令

您点击的链接对应于以下 MATLAB 命令：

请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)