Main Content

removeconstantrows

Process matrices by removing rows with constant values

Syntax

[Y,PS] = removeconstantrows(X,max_range)
[Y,PS] = removeconstantrows(X,FP)
Y = removeconstantrows('apply',X,PS)
X = removeconstantrows('reverse',Y,PS)

Description

removeconstantrows processes matrices by removing rows with constant values.

[Y,PS] = removeconstantrows(X,max_range) takes X and an optional parameter,

X

N-by-Q matrix

max_range

Maximum range of values for row to be removed (default is 0)

and returns

Y

M-by-Q matrix with N - M rows deleted

PS

Process settings that allow consistent processing of values

[Y,PS] = removeconstantrows(X,FP) takes parameters as a struct: FP.max_range.

Y = removeconstantrows('apply',X,PS) returns Y, given X and settings PS.

X = removeconstantrows('reverse',Y,PS) returns X, given Y and settings PS.

Any NaN values in the input matrix are treated as missing data, and are not considered as unique values. So, for example, removeconstantrows removes the first row from the matrix [1 1 1 NaN; 1 1 1 2].

Examples

Format a matrix so that the rows with constant values are removed.

x1 = [1 2 4; 1 1 1; 3 2 2; 0 0 0];
[y1,PS] = removeconstantrows(x1);
y1 =
     1     2     4
     3     2     2

PS = 
    max_range: 0
         keep: [1 3]
       remove: [2 4]
        value: [2x1 double]
        xrows: 4
        yrows: 2
    constants: [2x1 double]
    no_change: 0

Next, apply the same processing settings to new values.

x2 = [5 2 3; 1 1 1; 6 7 3; 0 0 0];
y2 = removeconstantrows('apply',x2,PS)
5     2     3
6     7     3

Reverse the processing of y1 to get the original x1 matrix.

x1_again = removeconstantrows('reverse',y1,PS)
1     2     4
1     1     1
3     2     2
0     0     0

Version History

Introduced in R2006a